Merge branch 'rr/rebase-autostash-fix' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 25 Jun 2014 18:49:31 +0000 (11:49 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 Jun 2014 18:49:31 +0000 (11:49 -0700)
The autostash mode of "git rebase -i" did not restore the dirty
working tree state if the user aborted the interactive rebase by
emptying the insn sheet.

* rr/rebase-autostash-fix:
rebase -i: test "Nothing to do" case with autostash
rebase -i: handle "Nothing to do" case with autostash

git-rebase--interactive.sh
git-rebase.sh
t/t3420-rebase-autostash.sh
index 6ec9d3cb40b1e96f75132a11eb625fd42e64885d..f267d8b6c3eea5c557e63814e40a9ef38b776354 100644 (file)
@@ -1049,14 +1049,14 @@ fi
 
 
 has_action "$todo" ||
-       die_abort "Nothing to do"
+       return 2
 
 cp "$todo" "$todo".backup
 git_sequence_editor "$todo" ||
        die_abort "Could not execute editor"
 
 has_action "$todo" ||
-       die_abort "Nothing to do"
+       return 2
 
 expand_todo_ids
 
index 4543815ffd6b0d49466edc3059f6d085b79ebf8a..47ca3b990ba38cf45de793d5c3186b36fa728e33 100755 (executable)
@@ -155,7 +155,7 @@ move_to_original_branch () {
        esac
 }
 
-finish_rebase () {
+apply_autostash () {
        if test -f "$state_dir/autostash"
        then
                stash_sha1=$(cat "$state_dir/autostash")
@@ -171,6 +171,10 @@ You can run "git stash pop" or "git stash drop" at any time.
 '
                fi
        fi
+}
+
+finish_rebase () {
+       apply_autostash &&
        git gc --auto &&
        rm -rf "$state_dir"
 }
@@ -186,6 +190,11 @@ run_specific_rebase () {
        if test $ret -eq 0
        then
                finish_rebase
+       elif test $ret -eq 2 # special exit status for rebase -i
+       then
+               apply_autostash &&
+               rm -rf "$state_dir" &&
+               die "Nothing to do"
        fi
        exit $ret
 }
index 90eb26493cd309da34687dffc939166069cd88c6..d783f03d3fc581eed08d8d2593e20ced3cbae200 100755 (executable)
@@ -167,4 +167,19 @@ testrebase "" .git/rebase-apply
 testrebase " --merge" .git/rebase-merge
 testrebase " --interactive" .git/rebase-merge
 
+test_expect_success 'abort rebase -i with --autostash' '
+       test_when_finished "git reset --hard" &&
+       echo uncommited-content >file0 &&
+       (
+               write_script abort-editor.sh <<-\EOF &&
+                       echo >"$1"
+               EOF
+               test_set_editor "$(pwd)/abort-editor.sh" &&
+               test_must_fail git rebase -i --autostash HEAD^ &&
+               rm -f abort-editor.sh
+       ) &&
+       echo uncommited-content >expected &&
+       test_cmp expected file0
+'
+
 test_done