Merge branch 'js/rebase-autostash-detach-fix'
authorJunio C Hamano <gitster@pobox.com>
Sun, 18 Nov 2018 09:23:55 +0000 (18:23 +0900)
committerJunio C Hamano <gitster@pobox.com>
Sun, 18 Nov 2018 09:23:55 +0000 (18:23 +0900)
"git rebase --autostash" did not correctly re-attach the HEAD at times.

* js/rebase-autostash-detach-fix:
built-in rebase --autostash: leave the current branch alone if possible
built-in rebase: demonstrate regression with --autostash

builtin/rebase.c
t/t3420-rebase-autostash.sh
index b84568fc4e6677e5f68c3b11e0798942ae19577a..6db1b7cc56fb274f56ba311f79296e9f2a373cd7 100644 (file)
@@ -613,7 +613,8 @@ static int reset_head(struct object_id *oid, const char *action,
                reflog_head = msg.buf;
        }
        if (!switch_to_branch)
-               ret = update_ref(reflog_head, "HEAD", oid, orig, REF_NO_DEREF,
+               ret = update_ref(reflog_head, "HEAD", oid, orig,
+                                detach_head ? REF_NO_DEREF : 0,
                                 UPDATE_REFS_MSG_ON_ERR);
        else {
                ret = create_symref("HEAD", switch_to_branch, msg.buf);
index f355c6825a4a5ff6adef656c432a4e2fdaf0fea9..4c7494cc8f77a3ff92373cb130974825c4418ada 100755 (executable)
@@ -361,4 +361,12 @@ test_expect_success 'autostash with dirty submodules' '
        git rebase -i --autostash HEAD
 '
 
+test_expect_success 'branch is left alone when possible' '
+       git checkout -b unchanged-branch &&
+       echo changed >file0 &&
+       git rebase --autostash unchanged-branch &&
+       test changed = "$(cat file0)" &&
+       test unchanged-branch = "$(git rev-parse --abbrev-ref HEAD)"
+'
+
 test_done