Skip to content

Commit 3a9156a

Browse files
sivaraamgitster
authored andcommitted
rebase: consistently use branch_name variable
The variable "branch_name" holds the <branch> parameter in "git rebase <upstream> <branch>", but one codepath did not use it after assigning $1 to it (instead it kept using $1). Make it use the variable consistently. Also, update an error message to say there is no such branch or commit, as we are expecting either of them, and not limiting ourselves to a branch name. Signed-off-by: Kaartic Sivaraam <[email protected]> Signed-off-by: Junio C Hamano <[email protected]> Signed-off-by: Kaartic Sivaraam <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 52015aa commit 3a9156a

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

git-rebase.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ case "$onto_name" in
518518
esac
519519

520520
# If the branch to rebase is given, that is the branch we will rebase
521-
# $branch_name -- branch being rebased, or HEAD (already detached)
521+
# $branch_name -- branch/commit being rebased, or HEAD (already detached)
522522
# $orig_head -- commit object name of tip of the branch before rebasing
523523
# $head_name -- refs/heads/<that-branch> or "detached HEAD"
524524
switch_to=
@@ -528,15 +528,18 @@ case "$#" in
528528
branch_name="$1"
529529
switch_to="$1"
530530

531-
if git show-ref --verify --quiet -- "refs/heads/$1" &&
532-
orig_head=$(git rev-parse -q --verify "refs/heads/$1")
531+
# Is it a local branch?
532+
if git show-ref --verify --quiet -- "refs/heads/$branch_name" &&
533+
orig_head=$(git rev-parse -q --verify "refs/heads/$branch_name")
533534
then
534-
head_name="refs/heads/$1"
535-
elif orig_head=$(git rev-parse -q --verify "$1")
535+
head_name="refs/heads/$branch_name"
536+
# If not is it a valid ref (branch or commit)?
537+
elif orig_head=$(git rev-parse -q --verify "$branch_name")
536538
then
537539
head_name="detached HEAD"
540+
538541
else
539-
die "$(eval_gettext "fatal: no such branch: \$branch_name")"
542+
die "$(eval_gettext "fatal: no such branch/commit: \$branch_name")"
540543
fi
541544
;;
542545
0)
@@ -547,7 +550,7 @@ case "$#" in
547550
branch_name=$(expr "z$branch_name" : 'zrefs/heads/\(.*\)')
548551
else
549552
head_name="detached HEAD"
550-
branch_name=HEAD ;# detached
553+
branch_name=HEAD
551554
fi
552555
orig_head=$(git rev-parse --verify HEAD) || exit
553556
;;

0 commit comments

Comments
 (0)