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

[PATCH v5 3/3] rebase: rebasing can also be done when HEAD is detached

From
Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Date
Dec 16, 2017, 09:03 UTC
Message-ID
<20171216090319.11902-4-kaartic.sivaraam@gmail.com>
In-Reply-To
<20171216090319.11902-1-kaartic.sivaraam@gmail.com>

Attempting to rebase when the HEAD is detached and is already up to date with upstream (so there's nothing to do), the following message is shown

        Current branch HEAD is up to date.
which is clearly wrong as HEAD is not a branch.

Handle the special case of HEAD correctly to give a more precise error message.

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>
---
 git-rebase.sh | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/git-rebase.sh b/git-rebase.sh
index 0f379ba2b..fd72a35c6 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -601,11 +601,23 @@ 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.")"
+		if test "$branch_name" = "HEAD" &&
+			 ! git symbolic-ref -q HEAD
+		then
+			say "$(eval_gettext "HEAD is up to date.")"
+		else
+			say "$(eval_gettext "Current branch \$branch_name is up to date.")"
+		fi
 		finish_rebase
 		exit 0
 	else
-		say "$(eval_gettext "Current branch \$branch_name is up to date, rebase forced.")"
+		if test "$branch_name" = "HEAD" &&
+			 ! git symbolic-ref -q HEAD
+		then
+			say "$(eval_gettext "HEAD is up to date, rebase forced.")"
+		else
+			say "$(eval_gettext "Current branch \$branch_name is up to date, rebase forced.")"
+		fi
 	fi
 fi
 
-- 
2.15.0.531.g2ccb3012c
Previous: Kaartic Sivaraam
Message 18 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.