Closed jonathanl-telenav closed 2 years ago
The limitation is git's. From the docs in CheckoutMojo:
If true, attempt to switch branches, even in the presence of local changes, if a local branch with the name of the target branch already exists. This can fail if the local changes depend on changes from a head other than the target branch's head commit. Ignored and the build files if there are local changes and the branch exists remotely but not locally.
In short, just as with using git on the command-line, you can often change branches with local changes - but not if the files you changed would get their content rewritten by changing branches - if that is the case, git will refuse to change branches and exit with an error.
Now, git is conservative about that - it might be possible that different regions would be modified in the file by switching branches - but since it cannot guarantee the file will be valid after stirring together local changes and differences from the branch, it doesn't try.
Conceivably we could attempt to create a patch from the local changes, revert them, change branches and then try to apply them - but it would sometimes result in garbage (say, a source file with reordered members that winds up with two copies of the same method).
this maven command:
mvn -Dorg.slf4j.simpleLogger.logFile="/var/folders/rm/1qd3sg1n6gx12kbf39xgp73w0000gn/T/maven-Wed-2022.07.30-17.14-telenav-checkout.log" -Dorg.slf4j.simpleLogger.defaultLogLevel="info" -Dorg.slf4j.simpleLogger.cacheOutputStream=false -Dcactus.fetch-first=true -Dcactus.base-branch=develop -Dcactus.target-branch="feature/cors" -Dcactus.update-root=true -Dcactus.include-root=true -Dcactus.create-branches=true -Dcactus.create-local-branches=true -Dcactus.push=false -Dcactus.permit-local-changes=true -Dcactus.scope=all com.telenav.cactus:cactus-maven-plugin:1.5.26:checkout validate
executed on the safety-service-build workspace, with all projects on the
develop
branch, unexpectedly fails to switch branches:would expect it to switch branches.
workaround: if I manually create the branch
feature/cors
the plugin then succeeds in switching all branches tofeature/cors
.