git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 1/3] rebase: use a more appropriate variable name

From
Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Date
Nov 27, 2017, 17:21 UTC
Message-ID
<20171127172104.5796-2-kaartic.sivaraam@gmail.com>
In-Reply-To
<20171127172104.5796-1-kaartic.sivaraam@gmail.com>

The variable name "branch_name" used to indicate the <branch> parameter in "git rebase <upstream> <branch>" is misleading as it seems to indicate that it holds only a "branch name" although at times it might actually hold any valid <ref> (branch/commit).

So, use a more suitable name for that variable.
Signed-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
---
 git-rebase.sh | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)
diff --git a/git-rebase.sh b/git-rebase.sh
index 6344e8d5e..a675cf691 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -518,36 +518,40 @@ case "$onto_name" in
 esac
 
 # If the branch to rebase is given, that is the branch we will rebase
-# $branch_name -- branch being rebased, or HEAD (already detached)
+# $branch_or_commit -- branch/commit being rebased, or HEAD (already detached)
 # $orig_head -- commit object name of tip of the branch before rebasing
 # $head_name -- refs/heads/<that-branch> or "detached HEAD"
 switch_to=
 case "$#" in
 1)
 	# Is it "rebase other $branchname" or "rebase other $commit"?
-	branch_name="$1"
+	branch_or_commit="$1"
 	switch_to="$1"
 
-	if git show-ref --verify --quiet -- "refs/heads/$1" &&
-	   orig_head=$(git rev-parse -q --verify "refs/heads/$1")
+	# Is it a local branch?
+	if git show-ref --verify --quiet -- "refs/heads/$branch_or_commit" &&
+	   orig_head=$(git rev-parse -q --verify "refs/heads/$branch_or_commit")
 	then
-		head_name="refs/heads/$1"
-	elif orig_head=$(git rev-parse -q --verify "$1")
+		head_name="refs/heads/$branch_or_commit"
+
+	# If not is it a valid ref (branch or commit)?
+	elif orig_head=$(git rev-parse -q --verify "$branch_or_commit")
 	then
 		head_name="detached HEAD"
+
 	else
-		die "$(eval_gettext "fatal: no such branch: \$branch_name")"
+		die "$(eval_gettext "fatal: no such branch/commit: \$branch_or_commit")"
 	fi
 	;;
 0)
 	# Do not need to switch branches, we are already on it.
-	if branch_name=$(git symbolic-ref -q HEAD)
+	if branch_or_commit=$(git symbolic-ref -q HEAD)
 	then
-		head_name=$branch_name
-		branch_name=$(expr "z$branch_name" : 'zrefs/heads/\(.*\)')
+		head_name=$branch_or_commit
+		branch_or_commit=$(expr "z$branch_or_commit" : 'zrefs/heads/\(.*\)')
 	else
 		head_name="detached HEAD"
-		branch_name=HEAD ;# detached
+		branch_or_commit="HEAD"
 	fi
 	orig_head=$(git rev-parse --verify HEAD) || exit
 	;;
@@ -598,11 +602,11 @@ then
 		test -z "$switch_to" ||
 		GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to" \
 			git checkout -q "$switch_to" --
-		say "$(eval_gettext "Current branch \$branch_name is up to date.")"
+		say "$(eval_gettext "Current branch \$branch_or_commit is up to date.")"
 		finish_rebase
 		exit 0
 	else
-		say "$(eval_gettext "Current branch \$branch_name is up to date, rebase forced.")"
+		say "$(eval_gettext "Current branch \$branch_or_commit is up to date, rebase forced.")"
 	fi
 fi
 
@@ -632,7 +636,7 @@ git update-ref ORIG_HEAD $orig_head
 # we just fast-forwarded.
 if test "$mb" = "$orig_head"
 then
-	say "$(eval_gettext "Fast-forwarded \$branch_name to \$onto_name.")"
+	say "$(eval_gettext "Fast-forwarded \$branch_or_commit to \$onto_name.")"
 	move_to_original_branch
 	finish_rebase
 	exit 0
-- 
2.15.0.345.gf926f18f3
Previous: Kaartic SivaraamNext: Kaartic Sivaraam
Message 4 of 18 in “rebase: rebasing can also be done when HEAD is detached”
  1. rebase: rebasing can also be done when HEAD is detachedKaartic Sivaraam, Nov 21, 2017
  2. Junio C HamanoNov 22, 2017
  3. 0/3 rebase: give precise error messageKaartic Sivaraam, Nov 27, 2017
  4. 1/3 rebase: use a more appropriate variable nameKaartic Sivaraam, Nov 27, 2017
  5. 2/3 rebase: distinguish user input by quoting itKaartic Sivaraam, Nov 27, 2017
  6. 3/3 rebase: rebasing can also be done when HEAD is detachedKaartic Sivaraam, Nov 27, 2017
  7. Junio C HamanoNov 28, 2017
  8. Kaartic SivaraamNov 28, 2017
  9. 3/3 rebase: rebasing can also be done when HEAD is detachedKaartic Sivaraam, Dec 1, 2017
  10. Junio C HamanoNov 28, 2017
  11. Kaartic SivaraamNov 28, 2017
  12. Junio C HamanoNov 29, 2017
  13. Kaartic SivaraamNov 29, 2017
  14. Junio C HamanoNov 29, 2017
  15. 0/3 rebase: give precise error messagesKaartic Sivaraam, Dec 16, 2017
  16. 1/3 rebase: consistently use branch_name variableKaartic Sivaraam, Dec 16, 2017
  17. 2/3 rebase: distinguish user input by quoting itKaartic Sivaraam, Dec 16, 2017
  18. 3/3 rebase: rebasing can also be done when HEAD is detachedKaartic Sivaraam, Dec 16, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.