Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 12 code review editor fails to open because it's unable to find the file in source control

Tags:

git

xcode

ios

swift

I have a main "app" folder that's the root of the git repository. Inside here, I have "ios-app" folder where my Xcode xcworkspace resides among other folders like "android-app", "backend", etc. Surprisingly, Xcode does show the status of the files (i.e. M for modified) and I am able to use Fetch Changes menu option, but I am unable to either commit with Xcode or view the file in the code review editor.

Error when opening code preview:

The source control operation failed because the file “...” could not be found.
Make sure a valid file exists in the repository and try again.

enter image description here

Error when committing:

The working copy “...” failed to commit files.
error: pathspec 'app/ios-app/DataModel/EventMutations.swift' did not match any file(s) known to git

enter image description here

Nothing interesting in Console app, but the below details may be relevant:

[MT] DVTAssertions: Warning in /Library/Caches/com.apple.xbs/Sources/IDEFrameworks/IDEFrameworks-17220/IDEKit/CommandsAndSelection/IDEMenuBuilder.m:203
Details:  Unknown submenu: "Xcode.IDEPegasusSourceEditor.MenuDefinition.SourceCodeAuxiliaryEditorMenuItem3" in menu: "Xcode.IDEPegasusSourceEditor.MenuDefinition.Editor"!
Object:   <IDEMenuBuilder>
Method:   +_menuItemForMenuItemElement:inMenuWithIdentifierUsedForDebugging:forViewController:fillingExtensionIdToMenuMap:
Thread:   <NSThread: 0x7fb3aa517540>{number = 1, name = main}
Please file a bug at https://feedbackassistant.apple.com with this warning message and any useful information you can provide.

At one point I did rename my folder from "iOS-app" to "ios-app" so to preclude the case that this might be git's case sensitivity, I did run git config --global core.ignorecase true, but this does not resolve the issue.

I have also tried to remove the project from Xcode's "Welcome to Xcode" page and add them back in case this affected how the gitpath is determined.

All file paths in Xcode seem correct and "Show in Folder" option always works.

I am also able to correctly view the git project in the Source Control Navigation:

enter image description here

like image 719
Zorayr Avatar asked Oct 14 '20 23:10

Zorayr


1 Answers

TL;DR: double check that the case of the local folders & files matches the case of the remote folders and files. Also, double check that your local project's case sensitivity has been enabled (local overrides global git settings), otherwise, git status will pretend that there is nothing going on.

In my case, I locally renamed iOS-app to ios-app, but did not push this to remote branch, so Xcode was trying to find the lower case version and couldn't!

Seems like Xcode by default has case sensitivity enabled, whereas git's can be configured.

  1. Enable local git project's git case sensitivity:
> git config core.ignorecase
true
> git config core.ignorecase false
  1. Check that git status is now showing the problems with case sensitivity:
> git status

New files detected:

ios-app/
android-app/
  1. Rename the folders to lower case and push. Now git doesn't make this easy, if you just do git mv iOS-app ios-app, it will not rename 😡. What you need to do is rename iOS-app to some temporary name, then back to ios-app.
> git mv iOS-app iOS-app-foo
> git mv iOS-app-foo ios-app

> git add -A
> git commit -m "Make sure that local and remote have the same case."
> git push

Restart Xcode and you should be good to go!

like image 111
Zorayr Avatar answered Oct 19 '22 14:10

Zorayr