{"thread":{"id":"33583","subject":"[PATCH] rebase: find orig_head unambiguously","startedAt":"2013-04-23T22:51:14Z","lastAt":"2013-04-23T23:31:27Z","messageCount":2,"participants":["Phil Hord","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"215277","messageId":"1366757474-29149-1-git-send-email-hordp@cisco.com","threadId":"33583","inReplyTo":null,"subject":"[PATCH] rebase: find orig_head unambiguously","fromName":"Phil Hord","fromEmail":"hordp@cisco.com","sentAt":"2013-04-23T22:51:14Z","receivedAt":"2013-04-23T22:51:14Z","isPatch":true,"sender":{"key":"phil.hord@gmail.com","avatar":"https://avatars.githubusercontent.com/u/123908?v=4"},"body":"When we 'git rebase $upstream', git uses 'rev-parse --verify\n$current_branch' to find ORIG_HEAD.  But if $current_branch\nis ambiguous, 'rev-parse --verify' emits a warning and returns\na SHA1 anyway.  When the wrong ambiguous choice is used,\ngit-rebase fails non-gracefully:  it emits a warning about\nfailing to lock $current_branch, an error about being unable to\ncheckout $current_branch again, and it might even decide the\nrebase is a fast-forward when it is not.\n\nIn the 'rebase $upstream' case, we already know the unambiguous\nspelling of $current_branch is \"HEAD\".  Fix git-rebase to find\n$orig_head unambiguously.\n\nAdd a test in t3400-rebase.sh which creates an ambiguous branch\nname and rebases it implicitly with 'git rebase $other'.\n\nSigned-off-by: Phil Hord <hordp@cisco.com>\n---\n git-rebase.sh     | 2 +-\n t/t3400-rebase.sh | 7 +++++++\n 2 files changed, 8 insertions(+), 1 deletion(-)\n\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex b2f1c76..2c692c3 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -473,7 +473,7 @@ case \"$#\" in\n \t\thead_name=\"detached HEAD\"\n \t\tbranch_name=HEAD ;# detached\n \tfi\n-\torig_head=$(git rev-parse --verify \"${branch_name}^0\") || exit\n+\torig_head=$(git rev-parse --verify HEAD) || exit\n \t;;\n *)\n \tdie \"BUG: unexpected number of arguments left to parse\"\ndiff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh\nindex f6cc102..b58fa1a 100755\n--- a/t/t3400-rebase.sh\n+++ b/t/t3400-rebase.sh\n@@ -101,7 +101,14 @@ test_expect_success 'HEAD was detached during rebase' '\n \ttest $(git rev-parse HEAD@{1}) != $(git rev-parse my-topic-branch@{1})\n '\n \n+test_expect_success 'rebase from ambiguous branch name' '\n+\tgit checkout -b topic side &&\n+\tgit rebase master\n+'\n+\n test_expect_success 'rebase after merge master' '\n+\tgit checkout --detach refs/tags/topic &&\n+\tgit branch -D topic &&\n \tgit reset --hard topic &&\n \tgit merge master &&\n \tgit rebase master &&\n-- \n1.8.2.1.854.g46dda50.dirty\n"},{"id":"215280","messageId":"7vobd4hlio.fsf@alter.siamese.dyndns.org","threadId":"33583","inReplyTo":"1366757474-29149-1-git-send-email-hordp@cisco.com","subject":"Re: [PATCH] rebase: find orig_head unambiguously","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-04-23T23:31:27Z","receivedAt":"2013-04-23T23:31:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Phil Hord <hordp@cisco.com> writes:\n\n> When we 'git rebase $upstream', git uses 'rev-parse --verify\n> $current_branch' to find ORIG_HEAD.  But if $current_branch\n> is ambiguous, 'rev-parse --verify' emits a warning and returns\n> a SHA1 anyway.  When the wrong ambiguous choice is used,\n> git-rebase fails non-gracefully:  it emits a warning about\n> failing to lock $current_branch, an error about being unable to\n> checkout $current_branch again, and it might even decide the\n> rebase is a fast-forward when it is not.\n>\n> In the 'rebase $upstream' case, we already know the unambiguous\n> spelling of $current_branch is \"HEAD\".  Fix git-rebase to find\n> $orig_head unambiguously.\n\nWell explained; $current_branch that never appears as a variable in\nthe section of the code in question made me scratch my head while\nreading it, though.\n\nWill queue; thanks.\n\n> Add a test in t3400-rebase.sh which creates an ambiguous branch\n> name and rebases it implicitly with 'git rebase $other'.\n>\n> Signed-off-by: Phil Hord <hordp@cisco.com>\n> ---\n>  git-rebase.sh     | 2 +-\n>  t/t3400-rebase.sh | 7 +++++++\n>  2 files changed, 8 insertions(+), 1 deletion(-)\n>\n> diff --git a/git-rebase.sh b/git-rebase.sh\n> index b2f1c76..2c692c3 100755\n> --- a/git-rebase.sh\n> +++ b/git-rebase.sh\n> @@ -473,7 +473,7 @@ case \"$#\" in\n>  \t\thead_name=\"detached HEAD\"\n>  \t\tbranch_name=HEAD ;# detached\n>  \tfi\n> -\torig_head=$(git rev-parse --verify \"${branch_name}^0\") || exit\n> +\torig_head=$(git rev-parse --verify HEAD) || exit\n>  \t;;\n>  *)\n>  \tdie \"BUG: unexpected number of arguments left to parse\"\n> diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh\n> index f6cc102..b58fa1a 100755\n> --- a/t/t3400-rebase.sh\n> +++ b/t/t3400-rebase.sh\n> @@ -101,7 +101,14 @@ test_expect_success 'HEAD was detached during rebase' '\n>  \ttest $(git rev-parse HEAD@{1}) != $(git rev-parse my-topic-branch@{1})\n>  '\n>  \n> +test_expect_success 'rebase from ambiguous branch name' '\n> +\tgit checkout -b topic side &&\n> +\tgit rebase master\n> +'\n> +\n>  test_expect_success 'rebase after merge master' '\n> +\tgit checkout --detach refs/tags/topic &&\n> +\tgit branch -D topic &&\n>  \tgit reset --hard topic &&\n>  \tgit merge master &&\n>  \tgit rebase master &&\n"}]}