Merge branch 'pb/merge-autostash-more'
The local changes stashed by "git merge --autostash" were lost when the merge failed in certain ways, which has been corrected. * pb/merge-autostash-more: merge: apply autostash if merge strategy fails merge: apply autostash if fast-forward fails Documentation: define 'MERGE_AUTOSTASH' merge: add missing word "strategy" to a message
This commit is contained in:
@ -154,7 +154,8 @@ endif::git-pull[]
|
|||||||
--autostash::
|
--autostash::
|
||||||
--no-autostash::
|
--no-autostash::
|
||||||
Automatically create a temporary stash entry before the operation
|
Automatically create a temporary stash entry before the operation
|
||||||
begins, and apply it after the operation ends. This means
|
begins, record it in the special ref `MERGE_AUTOSTASH`
|
||||||
|
and apply it after the operation ends. This means
|
||||||
that you can run the operation on a dirty worktree. However, use
|
that you can run the operation on a dirty worktree. However, use
|
||||||
with care: the final stash application after a successful
|
with care: the final stash application after a successful
|
||||||
merge might result in non-trivial conflicts.
|
merge might result in non-trivial conflicts.
|
||||||
|
@ -1561,6 +1561,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
|
|||||||
&head_commit->object.oid,
|
&head_commit->object.oid,
|
||||||
&commit->object.oid,
|
&commit->object.oid,
|
||||||
overwrite_ignore)) {
|
overwrite_ignore)) {
|
||||||
|
apply_autostash(git_path_merge_autostash(the_repository));
|
||||||
ret = 1;
|
ret = 1;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
@ -1709,6 +1710,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
|
|||||||
else
|
else
|
||||||
fprintf(stderr, _("Merge with strategy %s failed.\n"),
|
fprintf(stderr, _("Merge with strategy %s failed.\n"),
|
||||||
use_strategies[0]->name);
|
use_strategies[0]->name);
|
||||||
|
apply_autostash(git_path_merge_autostash(the_repository));
|
||||||
ret = 2;
|
ret = 2;
|
||||||
goto done;
|
goto done;
|
||||||
} else if (best_strategy == wt_strategy)
|
} else if (best_strategy == wt_strategy)
|
||||||
@ -1716,7 +1718,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
|
|||||||
else {
|
else {
|
||||||
printf(_("Rewinding the tree to pristine...\n"));
|
printf(_("Rewinding the tree to pristine...\n"));
|
||||||
restore_state(&head_commit->object.oid, &stash);
|
restore_state(&head_commit->object.oid, &stash);
|
||||||
printf(_("Using the %s to prepare resolving by hand.\n"),
|
printf(_("Using the %s strategy to prepare resolving by hand.\n"),
|
||||||
best_strategy);
|
best_strategy);
|
||||||
try_merge_strategy(best_strategy, common, remoteheads,
|
try_merge_strategy(best_strategy, common, remoteheads,
|
||||||
head_commit);
|
head_commit);
|
||||||
|
@ -122,6 +122,8 @@ test_expect_success 'setup' '
|
|||||||
c0=$(git rev-parse HEAD) &&
|
c0=$(git rev-parse HEAD) &&
|
||||||
cp file.1 file &&
|
cp file.1 file &&
|
||||||
git add file &&
|
git add file &&
|
||||||
|
cp file.1 other &&
|
||||||
|
git add other &&
|
||||||
test_tick &&
|
test_tick &&
|
||||||
git commit -m "commit 1" &&
|
git commit -m "commit 1" &&
|
||||||
git tag c1 &&
|
git tag c1 &&
|
||||||
@ -711,6 +713,15 @@ test_expect_success 'fast-forward merge with --autostash' '
|
|||||||
test_cmp result.1-5 file
|
test_cmp result.1-5 file
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'failed fast-forward merge with --autostash' '
|
||||||
|
git reset --hard c0 &&
|
||||||
|
git merge-file file file.orig file.5 &&
|
||||||
|
cp file.5 other &&
|
||||||
|
test_must_fail git merge --autostash c1 2>err &&
|
||||||
|
test_i18ngrep "Applied autostash." err &&
|
||||||
|
test_cmp file.5 file
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'octopus merge with --autostash' '
|
test_expect_success 'octopus merge with --autostash' '
|
||||||
git reset --hard c1 &&
|
git reset --hard c1 &&
|
||||||
git merge-file file file.orig file.3 &&
|
git merge-file file file.orig file.3 &&
|
||||||
@ -721,6 +732,14 @@ test_expect_success 'octopus merge with --autostash' '
|
|||||||
test_cmp result.1-3-5-9 file
|
test_cmp result.1-3-5-9 file
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'failed merge (exit 2) with --autostash' '
|
||||||
|
git reset --hard c1 &&
|
||||||
|
git merge-file file file.orig file.5 &&
|
||||||
|
test_must_fail git merge -s recursive --autostash c2 c3 2>err &&
|
||||||
|
test_i18ngrep "Applied autostash." err &&
|
||||||
|
test_cmp result.1-5 file
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'conflicted merge with --autostash, --abort restores stash' '
|
test_expect_success 'conflicted merge with --autostash, --abort restores stash' '
|
||||||
git reset --hard c3 &&
|
git reset --hard c3 &&
|
||||||
cp file.1 file &&
|
cp file.1 file &&
|
||||||
|
Reference in New Issue
Block a user