Skip to content

Commit 034195e

Browse files
newrengitster
authored andcommitted
merge: ensure we can actually restore pre-merge state
Merge strategies can: * succeed with a clean merge * succeed with a conflicted merge * fail to handle the given type of merge If one is thinking in terms of automatic mergeability, they would use the word "fail" instead of "succeed" for the second bullet, but I am focusing here on ability of the merge strategy to handle the given inputs, not on whether the given inputs are mergeable. The third category is about the merge strategy failing to know how to handle the given data; examples include: * Passing more than 2 branches to 'recursive' or 'ort' * Passing 2 or fewer branches to 'octopus' * Trying to do more complicated merges with 'resolve' (I believe directory/file conflicts will cause it to bail.) * Octopus running into a merge conflict for any branch OTHER than the final one (see the "exit 2" codepath of commit 98efc8f ("octopus: allow manual resolve on the last round.", 2006-01-13)) That final one is particularly interesting, because it shows that the merge strategy can muck with the index and working tree, and THEN bail and say "sorry, this strategy cannot handle this type of merge; use something else". Further, we do not currently expect the individual strategies to clean up after themselves, but instead expect builtin/merge.c to do so. For it to be able to, it needs to save the state before trying the merge strategy so it can have something to restore to. Therefore, remove the shortcut bypassing the save_state() call. There is another bug on the restore_state() side of things, so no testcase will be added until the next commit when we have addressed that issue as well. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aa77ce8 commit 034195e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

builtin/merge.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,12 +1682,12 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
16821682
* tree in the index -- this means that the index must be in
16831683
* sync with the head commit. The strategies are responsible
16841684
* to ensure this.
1685+
*
1686+
* Stash away the local changes so that we can try more than one
1687+
* and/or recover from merge strategies bailing while leaving the
1688+
* index and working tree polluted.
16851689
*/
1686-
if (use_strategies_nr == 1 ||
1687-
/*
1688-
* Stash away the local changes so that we can try more than one.
1689-
*/
1690-
save_state(&stash))
1690+
if (save_state(&stash))
16911691
oidclr(&stash);
16921692

16931693
for (i = 0; !merge_was_ok && i < use_strategies_nr; i++) {

0 commit comments

Comments
 (0)