]> git.ipfire.org Git - thirdparty/git.git/commitdiff
rebase: save autostash entry into stash reflog on --quit
authorDenton Liu <liu.denton@gmail.com>
Tue, 28 Apr 2020 09:31:31 +0000 (05:31 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 Apr 2020 19:35:38 +0000 (12:35 -0700)
In a03b55530a (merge: teach --autostash option, 2020-04-07), the
--autostash option was introduced for `git merge`. Notably, when
`git merge --quit` is run with an autostash entry present, it is saved
into the stash reflog. This is contrasted with the current behaviour of
`git rebase --quit` where the autostash entry is simply just dropped out
of existence.

Adopt the behaviour of `git merge --quit` in `git rebase --quit` and
save the autostash entry into the stash reflog instead of just deleting
it.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-rebase.txt
builtin/rebase.c
t/t3420-rebase-autostash.sh

index f7a6033607fa558dfd5a0437d7b4327ff1c44c78..7d0c89a18406203c60ccb19102de3ff8851c4644 100644 (file)
@@ -256,7 +256,8 @@ See also INCOMPATIBLE OPTIONS below.
 --quit::
        Abort the rebase operation but HEAD is not reset back to the
        original branch. The index and working tree are also left
-       unchanged as a result.
+       unchanged as a result. If a temporary stash entry was created
+       using --autostash, it will be saved to the stash reflog.
 
 --apply:
        Use applying strategies to rebase (calling `git-am`
index bc4fc699064c65078084b1308c8285803f10b731..71aec532b1d048ec0e312f6c74d61c07ba2778e0 100644 (file)
@@ -1556,6 +1556,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                goto cleanup;
        }
        case ACTION_QUIT: {
+               save_autostash(state_dir_path("autostash", &options));
                if (options.type == REBASE_MERGE) {
                        struct replay_opts replay = REPLAY_OPTS_INIT;
 
index b97ea623639486000a2ca26da253775add02356a..ca331733fbb58e7d9f4c2e27d186b24170e56b36 100755 (executable)
@@ -184,6 +184,26 @@ testrebase () {
                git checkout feature-branch
        '
 
+       test_expect_success "rebase$type: --quit" '
+               test_config rebase.autostash true &&
+               git reset --hard &&
+               git checkout -b rebased-feature-branch feature-branch &&
+               test_when_finished git branch -D rebased-feature-branch &&
+               echo dirty >>file3 &&
+               git diff >expect &&
+               test_must_fail git rebase$type related-onto-branch &&
+               test_path_is_file $dotest/autostash &&
+               test_path_is_missing file3 &&
+               git rebase --quit &&
+               test_when_finished git stash drop &&
+               test_path_is_missing $dotest/autostash &&
+               ! grep dirty file3 &&
+               git stash show -p >actual &&
+               test_cmp expect actual &&
+               git reset --hard &&
+               git checkout feature-branch
+       '
+
        test_expect_success "rebase$type: non-conflicting rebase, conflicting stash" '
                test_config rebase.autostash true &&
                git reset --hard &&