{"thread":{"id":"36704","subject":"[PATCH] rebase -i: handle \"Nothing to do\" case with autostash","startedAt":"2014-05-19T22:05:20Z","lastAt":"2014-05-20T18:34:17Z","messageCount":5,"participants":["Ramkumar Ramachandra","Eric Sunshine","Matthieu Moy","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"242209","messageId":"1400537120-9995-1-git-send-email-artagnon@gmail.com","threadId":"36704","inReplyTo":null,"subject":"[PATCH] rebase -i: handle \"Nothing to do\" case with autostash","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2014-05-19T22:05:20Z","receivedAt":"2014-05-19T22:05:20Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"When a user invokes\n\n  $ git rebase -i @~3\n\nwith dirty files and rebase.autostash turned on, and exits the $EDITOR\nwith an empty buffer, the autostash fails to apply. Although the primary\nfocus of rr/rebase-autostash was to get the git-rebase--backend.sh\nscripts to return control to git-rebase.sh, it missed this case in\ngit-rebase--interactive.sh. Since this case is unlike the other cases\nwhich return control for housekeeping, assign it a special return status\nand handle that return value explicitly in git-rebase.sh.\n\nReported-by: Karen Etheridge <ether@cpan.org>\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n Thanks to Karen for reporting this.\n\n I chose 2 arbitrarily. Let me know if you have a rationale for other\n return values.\n\n git-rebase--interactive.sh |  4 ++--\n git-rebase.sh              | 11 ++++++++++-\n 2 files changed, 12 insertions(+), 3 deletions(-)\n\ndiff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\nindex 6ec9d3c..f267d8b 100644\n--- a/git-rebase--interactive.sh\n+++ b/git-rebase--interactive.sh\n@@ -1049,14 +1049,14 @@ fi\n \n \n has_action \"$todo\" ||\n-\tdie_abort \"Nothing to do\"\n+\treturn 2\n \n cp \"$todo\" \"$todo\".backup\n git_sequence_editor \"$todo\" ||\n \tdie_abort \"Could not execute editor\"\n \n has_action \"$todo\" ||\n-\tdie_abort \"Nothing to do\"\n+\treturn 2\n \n expand_todo_ids\n \ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex 4543815..47ca3b9 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -155,7 +155,7 @@ move_to_original_branch () {\n \tesac\n }\n \n-finish_rebase () {\n+apply_autostash () {\n \tif test -f \"$state_dir/autostash\"\n \tthen\n \t\tstash_sha1=$(cat \"$state_dir/autostash\")\n@@ -171,6 +171,10 @@ You can run \"git stash pop\" or \"git stash drop\" at any time.\n '\n \t\tfi\n \tfi\n+}\n+\n+finish_rebase () {\n+\tapply_autostash &&\n \tgit gc --auto &&\n \trm -rf \"$state_dir\"\n }\n@@ -186,6 +190,11 @@ run_specific_rebase () {\n \tif test $ret -eq 0\n \tthen\n \t\tfinish_rebase\n+\telif test $ret -eq 2 # special exit status for rebase -i\n+\tthen\n+\t\tapply_autostash &&\n+\t\trm -rf \"$state_dir\" &&\n+\t\tdie \"Nothing to do\"\n \tfi\n \texit $ret\n }\n-- \n2.0.0.rc2.20.gfc2568d.dirty\n"},{"id":"242230","messageId":"1400568913-1340-1-git-send-email-Matthieu.Moy@imag.fr","threadId":"36704","inReplyTo":"1400537120-9995-1-git-send-email-artagnon@gmail.com","subject":"[PATCH] rebase -i: test \"Nothing to do\" case with autostash","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2014-05-20T06:55:13Z","receivedAt":"2014-05-20T06:55:13Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\nRam's patch lacks a test. Here it is. Fails without Ram's patch, and\npasses with it.\n\nCan be squashed into Ram's patch.\n\n t/t3420-rebase-autostash.sh | 17 +++++++++++++++++\n 1 file changed, 17 insertions(+)\n\ndiff --git a/t/t3420-rebase-autostash.sh b/t/t3420-rebase-autostash.sh\nindex 90eb264..c2e9a4c 100755\n--- a/t/t3420-rebase-autostash.sh\n+++ b/t/t3420-rebase-autostash.sh\n@@ -167,4 +167,21 @@ testrebase \"\" .git/rebase-apply\n testrebase \" --merge\" .git/rebase-merge\n testrebase \" --interactive\" .git/rebase-merge\n \n+test_expect_success 'Abort rebase with --autostash' '\n+\tgit log &&\n+\techo new-content >file0 &&\n+\t(\n+\t\twrite_script abort-editor.sh <<-\\EOF &&\n+\t\t\techo > \"$1\"\n+\t\tEOF\n+\t\tGIT_EDITOR=\\\"$(pwd)/abort-editor.sh\\\" &&\n+\t\texport GIT_EDITOR &&\n+\t\ttest_must_fail git rebase -i --autostash HEAD^ &&\n+\t\trm -f abort-editor.sh\n+\t) &&\n+\tgit status &&\n+\techo new-content >expected &&\n+\ttest_cmp expected file0\n+'\n+\n test_done\n-- \n2.0.0.rc3.499.gd6dc9ad\n"},{"id":"242223","messageId":"CAPig+cSWrc-W+9CZQ9vF-E3xcLY3OFoRMpHLb3K8Vsx3iz1Mjw@mail.gmail.com","threadId":"36704","inReplyTo":"1400568913-1340-1-git-send-email-Matthieu.Moy@imag.fr","subject":"Re: [PATCH] rebase -i: test \"Nothing to do\" case with autostash","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2014-05-20T07:22:15Z","receivedAt":"2014-05-20T07:22:15Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, May 20, 2014 at 2:55 AM, Matthieu Moy <Matthieu.Moy@imag.fr> wrote:\n> Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n> ---\n> Ram's patch lacks a test. Here it is. Fails without Ram's patch, and\n> passes with it.\n>\n> Can be squashed into Ram's patch.\n>\n>  t/t3420-rebase-autostash.sh | 17 +++++++++++++++++\n>  1 file changed, 17 insertions(+)\n>\n> diff --git a/t/t3420-rebase-autostash.sh b/t/t3420-rebase-autostash.sh\n> index 90eb264..c2e9a4c 100755\n> --- a/t/t3420-rebase-autostash.sh\n> +++ b/t/t3420-rebase-autostash.sh\n> @@ -167,4 +167,21 @@ testrebase \"\" .git/rebase-apply\n>  testrebase \" --merge\" .git/rebase-merge\n>  testrebase \" --interactive\" .git/rebase-merge\n>\n> +test_expect_success 'Abort rebase with --autostash' '\n> +       git log &&\n> +       echo new-content >file0 &&\n> +       (\n> +               write_script abort-editor.sh <<-\\EOF &&\n> +                       echo > \"$1\"\n> +               EOF\n> +               GIT_EDITOR=\\\"$(pwd)/abort-editor.sh\\\" &&\n> +               export GIT_EDITOR &&\n\nSimpler (replace above two lines):\n\n    test_set_editor \"$(pwd)/abort-editor.sh\" &&\n\n> +               test_must_fail git rebase -i --autostash HEAD^ &&\n> +               rm -f abort-editor.sh\n> +       ) &&\n> +       git status &&\n> +       echo new-content >expected &&\n> +       test_cmp expected file0\n> +'\n> +\n>  test_done\n> --\n> 2.0.0.rc3.499.gd6dc9ad\n"},{"id":"242231","messageId":"1400572171-28372-1-git-send-email-Matthieu.Moy@imag.fr","threadId":"36704","inReplyTo":"CAPig+cSWrc-W+9CZQ9vF-E3xcLY3OFoRMpHLb3K8Vsx3iz1Mjw@mail.gmail.com","subject":"[PATCH v2] rebase -i: test \"Nothing to do\" case with autostash","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2014-05-20T07:49:31Z","receivedAt":"2014-05-20T07:49:31Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\nEric Sunshine <sunshine@sunshineco.com> writes:\n\n> Simpler (replace above two lines):\n>\n>     test_set_editor \"$(pwd)/abort-editor.sh\" &&\n\nIndeed.\n\nAnd I had debug statements left.\n\nHopefully, this after-coffee-v2 will be clear enough and correct ;-).\n\n t/t3420-rebase-autostash.sh | 15 +++++++++++++++\n 1 file changed, 15 insertions(+)\n\ndiff --git a/t/t3420-rebase-autostash.sh b/t/t3420-rebase-autostash.sh\nindex 90eb264..ff1e2dc 100755\n--- a/t/t3420-rebase-autostash.sh\n+++ b/t/t3420-rebase-autostash.sh\n@@ -167,4 +167,19 @@ testrebase \"\" .git/rebase-apply\n testrebase \" --merge\" .git/rebase-merge\n testrebase \" --interactive\" .git/rebase-merge\n \n+test_expect_success 'abort rebase -i with --autostash' '\n+\ttest_when_finished \"git reset --hard\" &&\n+\techo uncommited-content >file0 &&\n+\t(\n+\t\twrite_script abort-editor.sh <<-\\EOF &&\n+\t\t\techo > \"$1\"\n+\t\tEOF\n+\t\ttest_set_editor \"$(pwd)/abort-editor.sh\" &&\n+\t\ttest_must_fail git rebase -i --autostash HEAD^ &&\n+\t\trm -f abort-editor.sh\n+\t) &&\n+\techo uncommited-content >expected &&\n+\ttest_cmp expected file0\n+'\n+\n test_done\n-- \n2.0.0.rc3.499.gd6dc9ad\n"},{"id":"242303","messageId":"xmqqfvk4z4d2.fsf@gitster.dls.corp.google.com","threadId":"36704","inReplyTo":"1400572171-28372-1-git-send-email-Matthieu.Moy@imag.fr","subject":"Re: [PATCH v2] rebase -i: test \"Nothing to do\" case with autostash","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-05-20T18:34:17Z","receivedAt":"2014-05-20T18:34:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matthieu Moy <Matthieu.Moy@imag.fr> writes:\n\n> Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n> ---\n> Eric Sunshine <sunshine@sunshineco.com> writes:\n>\n>> Simpler (replace above two lines):\n>>\n>>     test_set_editor \"$(pwd)/abort-editor.sh\" &&\n>\n> Indeed.\n>\n> And I had debug statements left.\n>\n> Hopefully, this after-coffee-v2 will be clear enough and correct ;-).\n\nThanks, will queue on top of Ram's fix.\n"}]}