Telenav / cactus

Modules for building the KivaKit Java framework.
Apache License 2.0
0 stars 1 forks source link

-Dcactus.permit-local-changes=true fails #53

Closed jonathanl-telenav closed 2 years ago

jonathanl-telenav commented 2 years ago

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:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  10.610 s
[INFO] Finished at: 2022-08-30T17:14:23-06:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.telenav.cactus:cactus-maven-plugin:1.5.26:checkout (default-cli) on project safety-service-uber-bom: Cannot change all branches to 'feature/cors:
**[ERROR] Have local changes in kivakit-extensions - cannot proceed to change to branch feature/cors**
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :safety-service-uber-bom

would expect it to switch branches.

workaround: if I manually create the branch feature/cors the plugin then succeeds in switching all branches to feature/cors.

timboudreau commented 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).