{"thread":{"id":"25474","subject":"Possible bug in \"git rebase\" (non-interactive) with regards to post-rewrite","startedAt":"2010-10-18T22:39:44Z","lastAt":"2010-12-26T10:38:20Z","messageCount":4,"participants":["Mihai Rusu","Junio C Hamano","Thomas Rast"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"153753","messageId":"AANLkTikv+TuVK3uyEd5ymLRq6Qs7tQYm4kUH3t9hTtQP@mail.gmail.com","threadId":"25474","inReplyTo":null,"subject":"Possible bug in \"git rebase\" (non-interactive) with regards to post-rewrite","fromName":"Mihai Rusu","fromEmail":"dizzy@google.com","sentAt":"2010-10-18T22:39:44Z","receivedAt":"2010-10-18T22:39:44Z","isPatch":false,"sender":{"key":"dizzy@google.com","avatar":null},"body":"Hi\n\nI have found a possible bug in Git. When running \"git rebase\"\n(non-interactively, ie not \"git rebase -i\") on code that would\nconflict on the last commit that is being rebased and if that last\ncommit is being skipped (git rebase --skip) then after the rebase is\ndone the \"post-rewrite\" hook is not called by \"git rebase\". If I get a\nconflict and \"git rebase --skip\" any other commit or if I use \"git\nrebase -i\" and \"git rebase --skip\" the last commit when it conflicts\nthen it calls post-rewrite just fine. Because this hook is normally\ncalled only once, at the end of a non-aborted rebase the fact that\n\"git rebase\" does not call it when the last commit conflicts and is\nskipped means the script is not called at all for that rebase\noperation thus breaking the code that depends on it.\n\nPlease advise, thank you.\n\n-- \nMihai Rusu\n"},{"id":"158512","messageId":"7vipyl4aqx.fsf@alter.siamese.dyndns.org","threadId":"25474","inReplyTo":"AANLkTikv+TuVK3uyEd5ymLRq6Qs7tQYm4kUH3t9hTtQP@mail.gmail.com","subject":"Re: Possible bug in \"git rebase\" (non-interactive) with regards to post-rewrite","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-12-23T00:02:30Z","receivedAt":"2010-12-23T00:02:30Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Mihai Rusu <dizzy@google.com> writes:\n\n> I have found a possible bug in Git. When running \"git rebase\"\n> (non-interactively, ie not \"git rebase -i\") on code that would\n> conflict on the last commit that is being rebased and if that last\n> commit is being skipped (git rebase --skip) then after the rebase is\n> done the \"post-rewrite\" hook is not called by \"git rebase\". If I get a\n> conflict and \"git rebase --skip\" any other commit or if I use \"git\n> rebase -i\" and \"git rebase --skip\" the last commit when it conflicts\n> then it calls post-rewrite just fine. Because this hook is normally\n> called only once, at the end of a non-aborted rebase the fact that\n> \"git rebase\" does not call it when the last commit conflicts and is\n> skipped means the script is not called at all for that rebase\n> operation thus breaking the code that depends on it.\n>\n> Please advise, thank you.\n\nPerhaps this?  Totally untested...\n\n git-am.sh |    7 -------\n 1 files changed, 0 insertions(+), 7 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex cf1f64b..6cdd591 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -577,13 +577,6 @@ then\n \tresume=\n fi\n \n-if test \"$this\" -gt \"$last\"\n-then\n-\tsay Nothing to do.\n-\trm -fr \"$dotest\"\n-\texit\n-fi\n-\n while test \"$this\" -le \"$last\"\n do\n \tmsgnum=`printf \"%0${prec}d\" $this`\n"},{"id":"158516","messageId":"7vd3ot48ke.fsf@alter.siamese.dyndns.org","threadId":"25474","inReplyTo":"7vipyl4aqx.fsf@alter.siamese.dyndns.org","subject":"Re: Possible bug in \"git rebase\" (non-interactive) with regards to post-rewrite","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-12-23T00:49:37Z","receivedAt":"2010-12-23T00:49:37Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"When \"rebase --skip\" is used to skip the last patch in the series, the\ncode to wrap up the rewrite by copying the notes from old to new commits\nand also by running the post-rewrite hook was bypassed.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n git-am.sh                    |    7 -------\n t/t5407-post-rewrite-hook.sh |   18 +++++++++++++++++-\n 2 files changed, 17 insertions(+), 8 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex de116a2..69474e5 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -554,13 +554,6 @@ then\n \tresume=\n fi\n \n-if test \"$this\" -gt \"$last\"\n-then\n-\tsay Nothing to do.\n-\trm -fr \"$dotest\"\n-\texit\n-fi\n-\n while test \"$this\" -le \"$last\"\n do\n \tmsgnum=`printf \"%0${prec}d\" $this`\ndiff --git a/t/t5407-post-rewrite-hook.sh b/t/t5407-post-rewrite-hook.sh\nindex 552da65..baa670c 100755\n--- a/t/t5407-post-rewrite-hook.sh\n+++ b/t/t5407-post-rewrite-hook.sh\n@@ -10,7 +10,11 @@ test_expect_success 'setup' '\n \ttest_commit A foo A &&\n \ttest_commit B foo B &&\n \ttest_commit C foo C &&\n-\ttest_commit D foo D\n+\ttest_commit D foo D &&\n+\tgit checkout A^0 &&\n+\ttest_commit E bar E &&\n+\ttest_commit F foo F &&\n+\tgit checkout master\n '\n \n mkdir .git/hooks\n@@ -79,6 +83,18 @@ EOF\n \tverify_hook_input\n '\n \n+test_expect_success 'git rebase --skip the last one' '\n+\tgit reset --hard F &&\n+\tclear_hook_input &&\n+\ttest_must_fail git rebase --onto D A &&\n+\tgit rebase --skip &&\n+\techo rebase >expected.args &&\n+\tcat >expected.data <<EOF &&\n+$(git rev-parse E) $(git rev-parse HEAD)\n+EOF\n+\tverify_hook_input\n+'\n+\n test_expect_success 'git rebase -m' '\n \tgit reset --hard D &&\n \tclear_hook_input &&\n"},{"id":"158585","messageId":"201012261138.21059.trast@student.ethz.ch","threadId":"25474","inReplyTo":"7vd3ot48ke.fsf@alter.siamese.dyndns.org","subject":"Re: Possible bug in \"git rebase\" (non-interactive) with regards to post-rewrite","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2010-12-26T10:38:20Z","receivedAt":"2010-12-26T10:38:20Z","isPatch":false,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Junio C Hamano wrote:\n> When \"rebase --skip\" is used to skip the last patch in the series, the\n> code to wrap up the rewrite by copying the notes from old to new commits\n> and also by running the post-rewrite hook was bypassed.\n> \n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n[...]\n> -if test \"$this\" -gt \"$last\"\n> -then\n> -\tsay Nothing to do.\n> -\trm -fr \"$dotest\"\n> -\texit\n> -fi\n> -\n>  while test \"$this\" -le \"$last\"\n>  do\n>  \tmsgnum=`printf \"%0${prec}d\" $this`\n\nAck, thanks for patching this.\n\n(I think it's saner anyway not to say \"nothing to do\" when the user\nwould expect \"we're all done here\"...)\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"}]}