Package.resolved modified unexpectedly when switching git branches outside of Xcode

We've recently increased our use of SPM in our iOS app's Xcode project. However, we've noticed that if the Xcode project is open when we switch to a different git branch using another tool (e.g. git on the command line or in a 3rd-party GUI), the Package.resolved file is modified unexpectedly.

We've received some conflicting advice about the purpose and appropriate treatment of the Package.resolved file. Some say to add it to .gitignore. On the other hand, the docs say:

…be sure to commit your project’s Package.resolved file to your Git repository. This ensures a reliable CI workflow that always uses the expected version of a package dependency.

For now, our workaround is to use Xcode to switch git branches, but this seems like an unusual limitation.

We're on Xcode 15.3/15.4.

There is discussion on the Swift Forums of potentially related problems: https://forums.swift.org/t/xcode-automatically-updating-package-resolved/41900

Also, to clarify — we believe that Xcode is responsible for making the unexpected modifications to Package.resolved for several reasons:

  • The unexpected edits do not occur if the project is not open in Xcode
  • None of the other files in our project are impacted by this problem when changing branches
  • It seems unlikely that 3rd-party tools like the git CLI would contain special treatment for the Package.resolved file.

Another update on this issue — I'm now able to repro the issue when switching branches using Xcode as well as 3rd-party git clients.

Also, using FSMonitor (https://fsmonitor.com), I've confirmed that Xcode is the process that modifies Package.resolved unexpectedly.

Xcode modifies the Package.resolved file only when it needs to, such as if you tell Xcode to update to the latest package versions through commands in the UI, or if the new git checkout has package version incompatibilities that require resolution.

I discussed the exact set of behaviors you’re seeing here with some colleagues, and there are some aspects to what you wrote that we want to look into further with a bug report. When creating the bug, please be as detailed as you are able, we appreciate it. Once you open the bug report, please post the FB number here for my reference. If you have any questions about filing a bug report, take a look at Bug Reporting: How and Why?

Thanks for the reply. Here's the bug report: FB14095059

Package.resolved modified unexpectedly when switching git branches outside of Xcode
 
 
Q