From a03b55530ab844974b7058042a015fcfcd9e7a53 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Tue, 7 Apr 2020 10:28:07 -0400 Subject: merge: teach --autostash option In rebase, one can pass the `--autostash` option to cause the worktree to be automatically stashed before continuing with the rebase. This option is missing in merge, however. Implement the `--autostash` option and corresponding `merge.autoStash` option in merge which stashes before merging and then pops after. This option is useful when a developer has some local changes on a topic branch but they realize that their work depends on another branch. Previously, they had to run something like git fetch ... git stash push git merge FETCH_HEAD git stash pop but now, that is reduced to git fetch ... git merge --autostash FETCH_HEAD When an autostash is generated, it is automatically reapplied to the worktree only in three explicit situations: 1. An incomplete merge is commit using `git commit`. 2. A merge completes successfully. 3. A merge is aborted using `git merge --abort`. In all other situations where the merge state is removed using remove_merge_branch_state() such as aborting a merge via `git reset --hard`, the autostash is saved into the stash reflog instead keeping the worktree clean. Helped-by: Phillip Wood Suggested-by: Alban Gruin Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- builtin/commit.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'builtin/commit.c') diff --git a/builtin/commit.c b/builtin/commit.c index 7ba33a3bec..c1b25d2954 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1713,6 +1713,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix) &oid, flags); } + apply_autostash(git_path_merge_autostash(the_repository)); + UNLEAK(err); UNLEAK(sb); return 0; -- cgit v1.2.3