Skip to content

Commit ea70980

Browse files
phordgitster
authored andcommitted
rebase: find orig_head unambiguously
When we 'git rebase $upstream', git uses 'rev-parse --verify $current_branch' to find ORIG_HEAD. But if $current_branch is ambiguous, 'rev-parse --verify' emits a warning and returns a SHA1 anyway. When the wrong ambiguous choice is used, git-rebase fails non-gracefully: it emits a warning about failing to lock $current_branch, an error about being unable to checkout $current_branch again, and it might even decide the rebase is a fast-forward when it is not. In the 'rebase $upstream' case, we already know the unambiguous spelling of $current_branch is "HEAD". Fix git-rebase to find $orig_head unambiguously. Add a test in t3400-rebase.sh which creates an ambiguous branch name and rebases it implicitly with 'git rebase $other'. Signed-off-by: Phil Hord <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7e20105 commit ea70980

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

git-rebase.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ case "$#" in
464464
head_name="detached HEAD"
465465
branch_name=HEAD ;# detached
466466
fi
467-
orig_head=$(git rev-parse --verify "${branch_name}^0") || exit
467+
orig_head=$(git rev-parse --verify HEAD) || exit
468468
;;
469469
*)
470470
die "BUG: unexpected number of arguments left to parse"

t/t3400-rebase.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,14 @@ test_expect_success 'HEAD was detached during rebase' '
101101
test $(git rev-parse HEAD@{1}) != $(git rev-parse my-topic-branch@{1})
102102
'
103103

104+
test_expect_success 'rebase from ambiguous branch name' '
105+
git checkout -b topic side &&
106+
git rebase master
107+
'
108+
104109
test_expect_success 'rebase after merge master' '
110+
git checkout --detach refs/tags/topic &&
111+
git branch -D topic &&
105112
git reset --hard topic &&
106113
git merge master &&
107114
git rebase master &&

0 commit comments

Comments
 (0)