20

I'm trying to use the shared rerere cache to automate throwaway integration/test branches.

The idea is that the rerere cache should be up to date when the branch is pushed, so that these merges always pass. However, they don't:

>>> git merge --no-ff invoicing
Staged 'analysisrequest.py' using previous resolution.
Staged '__init__.py' using previous resolution.
Auto-merging __init__.py
CONFLICT (content): Merge conflict in __init__.py
Auto-merging analysisrequest.py
CONFLICT (content): Merge conflict in analysisrequest.py
Automatic merge failed; fix conflicts and then commit the result.

At this point, rerere has staged the resolutions that it remembered, and no actual conflict exists. I can run git commit, then continue, but my integration-test-build script sees an error. I've tried adding --rerere-autoupdate to the git merge command, but nothing changes. I have configured the repo to enable and auto-apply rerere matches.

How can I ask git merge to use my previous resolutions and continue without failing if they are sufficient?

hlovdal
  • 26,565
  • 10
  • 94
  • 165
Campbell
  • 705
  • 3
  • 12
  • The situation should improve soon with Git 2.14.x/2.15 (Q3 2017): https://stackoverflow.com/a/45988818/6309 – VonC Aug 31 '17 at 19:32

1 Answers1

18

Even with the --rerere-autoupdate flag, git merge seems to be reluctant to automatically complete the merge without some human input. Instead, it executes with an error status, and your integration tool refuses to proceed.

I do not know how your automatic merging is happening, namely, whether you can change the Git command that is executed. If you can, then you can execute the following commands.

git merge --no-ff branch-to-merge --rerere-autoupdate
if [[ $(git rerere diff) ]]
then
    $(exit 1)
else
    git commit --no-edit
fi
  • git rerere diff lists files that need to be resolved after rerere.
  • --no-edit is necessary to prevent opening the commit message editor.
  • In case rerere was not able to cleanly merge all changes, this statement will still return with an error status and the merge will not be committed.
  • The commit message will still contain the conflicting files.
  • exit 1 needs to be inside $() unless you want to exit your shell. (Guess how I know this. :-))
Emil Laine
  • 41,598
  • 9
  • 101
  • 157
Joseph K. Strauss
  • 4,683
  • 1
  • 23
  • 40
  • 3
    The usual way to avoid `$(exit 1)` is to use the standard UNIX `false` (or `true`) commands – sehe Jan 06 '17 at 11:49