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 <kaartic.sivaraam@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Kaartic Sivaraam committed
Dec 16, 2017 at 14:33 UTC
3a9156adc774f28b3b0f880cdd285a7e01118d15
1 file changed
+10
-7
git-rebase.sh
+10
-7
@@ -518,7 +518,7 @@ case "$onto_name" in
518
esac
519
520
# 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)
522
# $orig_head -- commit object name of tip of the branch before rebasing
523
# $head_name -- refs/heads/<that-branch> or "detached HEAD"
524
switch_to=
@@ -528,15 +528,18 @@ case "$#" in
528
branch_name="$1"
529
switch_to="$1"
530
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")
534
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")
538
then
539
head_name="detached HEAD"
540
+
541
else
539
- die "$(eval_gettext "fatal: no such branch: \$branch_name")"
542
+ die "$(eval_gettext "fatal: no such branch/commit: \$branch_name")"
543
fi
544
;;
545
0)
@@ -547,7 +550,7 @@ case "$#" in
550
branch_name=$(expr "z$branch_name" : 'zrefs/heads/\(.*\)')
551
else
552
head_name="detached HEAD"
550
- branch_name=HEAD ;# detached
553
+ branch_name=HEAD
554
fi
555
orig_head=$(git rev-parse --verify HEAD) || exit
556
;;