Mattia Valzelli

Xcode Does Not Handle Git `includeIf`

Posted
by Mattia Valzelli
2 min.

Xcode Git

I’ve been using the Swift Package Manager Xcode integration since its introduction in Xcode 11 but was constantly hitting the following error while trying to check out any dependency.

Xcode showing the message when trying to add a Swift Package Manager dependency

The only way to add it to the project was to star it in GitHub and select it from the list. A couple of months ago I was fed up with this situation and promised myself that I would dive deep to understand why it was happening, given that every other person I know using the integration was functioning perfectly.

After a couple hours, with no progress I tried to setup Xcode on my home machine, an iMac that was never setup for development. To my surprise the SPM integration was working flawlessly!

So the problem was my development machine. To understand what could possibly be the problem I started to dived the problem into layers, staring with the most user facing, Xcode. The Xcode version used on the working machine was the same as the development one, so that was not it. Even the GitHub integration used in the Xcode accounts setting page was the same, down to the same key that I imported into the iMac from the development machine. So Xcode seemed to be ok (spoiler: it wasn’t).

The next suspect was git : on the working Mac the only git instance was the one included with Xcode, but on the development Mac I had also installed a version from Homebrew. While looking in the Xcode “Source Control” settings I noticed that Xcode was not picking up the “Author Name” and “Author Email” settings, but correctly using the “Ignored Files” defined in my ~/.gitignore.

That seemed strange to me, so I started looking into my ~/.gitconfig file, to understand why email and author where not picked up by Xcode. The email and author were not directly included in the configuration file, but they were loading conditionally by using the includeIf directive (defined for different project paths). Given that was the only noteworthy section in the gitconfig file I tried embedding the email and author field directly, and boom the error was gone (and the Xcode source control settings were correctly displaying)!

So it seems that Xcode does not like the includeIf directive in the configuration file.