An unknown error occured. reference 'refs/remotes/origin/master' not found (-1)

All of my packages are currently having this error everytime Xcode tries to resolve them. I can't add them as dependencies, I can't update them, I can't build.

I have to reset my package caches then update the packages for it to work once, in the current session, then it breaks again.

Some of these packages reference the master branch but other reference unrelated branches and don't have a master branch, doesn't seem to matter.

The only common point is that they're private bitbucket URLs in the format git@bitbucket.org:mycompany/my-repo.git. I'm also having issues with Xcode not being able to log in to the bitbucket account but it can still resolve and download those repos sometimes, so I'm not sure what's going on here.

Anybody else experienced this issue?

Is this reproducible for you outside of Xcode on the command line with swift build? If not, then the issue appears to be specific to Xcode, and that's out of scope of this forum and should be tracked at https://feedbackassistant.apple.com/

It seems to be related to issues with DerivedData so it seems to be Xcode

If any of the fine Apple folks are listening, I have today filed a feedback FB13428167.

In short, what I have found is that when Xcode initially resolves package dependencies, and clones everything into DerivedData it will include refs/remotes for each git@github.com dependency. Not sure why it does that and how, but refs/remotes is never present for any public https:// backed dependency. Only for git@ ones.

This refs/remotes directory will then somehow confuse Xcode and "Update to Latest Package Versions" will always fail with the error mentioned above.

Removing the refs/remotes directory will make Xcode happy indefinitely, until you delete the DerivedData folder, when the mess starts again.

I am currently using the following script to make the Xcode happy even while it is running (Note that I am also cleaning the ~/Library/org.swift.swiftpm repository clones, but this proved to not be necessary for Xcode to work. The DerivedData bit is what is important).

€ cat ~/fix_spm_cache.sh 
#!/bin/zsh

echo "Looking for problematic dirs..."

find ~/Library/Caches/org.swift.swiftpm/ -name remotes -type d
find ~/Library/Developer/Xcode/DerivedData/ -name remotes -type d | grep -vw checkouts

echo "Getting rid of them..."

find ~/Library/Caches/org.swift.swiftpm/ -name remotes -type d | xargs rm -r
find ~/Library/Developer/Xcode/DerivedData/ -name remotes -type d | grep -vw checkouts | xargs rm -r

This issue has been present in Xcode since initial SPM support was introduced and according to my experience it strictly affects only git@github.com based dependencies. The git@ dependencies work great in Swift Package Manager itself nicely, only Xcode is affected.

Add git@bitbucket.org to the list, thank you for the experimentation and the script, it'll definitely help out!

This looks like a very frustrating bug, and I think i am encountering the same issue.

Do you think perhaps another potential workaround would be to convert every dependency from using an https:// url to using a git@ url? Perhaps then, a script wouldn't be necessary.

I'll try that now and report back.