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

[PATCH v2 7/7] rebase -i: write better reflog messages

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
Jun 18, 2013, 18:55 UTC
Message-ID
<1371581737-10013-8-git-send-email-artagnon@gmail.com>
In-Reply-To
<1371581737-10013-1-git-send-email-artagnon@gmail.com>

Now that the "checkout" invoked internally from "rebase -i" knows to honor GIT_REFLOG_ACTION, we can start to use it to write a better reflog message when "rebase -i anotherbranch", "rebase -i --onto branch", etc. internally checks out the new fork point. We will write:

  rebase -i (start): checkout master
instead of the old
  rebase -i (start)
[jc: add rebase-reflog test]
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 git-rebase--interactive.sh    | 14 ++++++++++----
 t/t3404-rebase-interactive.sh | 15 +++++++++++++++
 2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index f953d8d..8429c87 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -95,12 +95,15 @@ commit_message () {
 	git cat-file commit "$1" | sed "1,/^$/d"
 }
 
-orig_reflog_action="$GIT_REFLOG_ACTION"
+base_reflog_action="$GIT_REFLOG_ACTION"
 
 comment_for_reflog () {
-	case "$orig_reflog_action" in
+	case "$base_reflog_action" in
+	# if GIT_REFLOG_ACTION was set by caller git-rebase, overwrite
+	# it with rebase -i.
 	''|rebase*)
 		GIT_REFLOG_ACTION="rebase -i ($1)"
+		base_reflog_action="$GIT_REFLOG_ACTION"
 		export GIT_REFLOG_ACTION
 		;;
 	esac
@@ -326,6 +329,7 @@ pick_one_preserving_merges () {
 		if [ "$1" != "-n" ]
 		then
 			# detach HEAD to current parent
+			GIT_REFLOG_ACTION="$base_reflog_action: checkout $first_parent"
 			output git checkout $first_parent 2> /dev/null ||
 				die "Cannot move HEAD to $first_parent"
 		fi
@@ -608,10 +612,10 @@ do_next () {
 	newhead=$(git rev-parse HEAD) &&
 	case $head_name in
 	refs/*)
-		message="$GIT_REFLOG_ACTION: $head_name onto $onto" &&
+		message="$base_reflog_action: $head_name onto $onto" &&
 		git update-ref -m "$message" $head_name $newhead $orig_head &&
 		git symbolic-ref \
-		  -m "$GIT_REFLOG_ACTION: returning to $head_name" \
+		  -m "$base_reflog_action: returning to $head_name" \
 		  HEAD $head_name
 		;;
 	esac && {
@@ -838,6 +842,7 @@ comment_for_reflog start
 
 if test ! -z "$switch_to"
 then
+	GIT_REFLOG_ACTION="$base_reflog_action: checkout $switch_to"
 	output git checkout "$switch_to" -- ||
 		die "Could not checkout $switch_to"
 fi
@@ -981,6 +986,7 @@ has_action "$todo" ||
 
 test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks
 
+GIT_REFLOG_ACTION="$base_reflog_action: checkout $onto_name"
 output git checkout $onto || die_abort "could not detach HEAD"
 git update-ref ORIG_HEAD $orig_head
 do_rest
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 79e8d3c..f7d0147 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -934,6 +934,21 @@ test_expect_success 'rebase --edit-todo can be used to modify todo' '
 	test L = $(git cat-file commit HEAD | sed -ne \$p)
 '
 
+test_expect_success 'rebase -i produces readable reflog' '
+	git reset --hard &&
+	git branch -f branch1 H &&
+	git rebase -i --onto I F branch1 &&
+	cat >expect <<-\EOF &&
+	rebase -i (start): checkout I
+	rebase -i (pick): G
+	rebase -i (pick): H
+	rebase -i (finish): returning to refs/heads/branch1
+	EOF
+	tail -n 4 .git/logs/HEAD |
+	sed -e "s/.*	//" >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'rebase -i respects core.commentchar' '
 	git reset --hard &&
 	git checkout E^0 &&
-- 
1.8.3.1.455.g5932b31
Previous: Junio C HamanoNext: Junio C Hamano
Message 15 of 19 in “Re-roll rr/rebase-checkout-reflog”
  1. 0/7 Re-roll rr/rebase-checkout-reflogRamkumar Ramachandra, Jun 18, 2013
  2. 1/7 t/t7512-status-help: test "HEAD detached from"Ramkumar Ramachandra, Jun 18, 2013
  3. 2/7 wt-status: remove unused field in grab_1st_switch_cbdataRamkumar Ramachandra, Jun 18, 2013
  4. 3/7 t/t2012-checkout-last: test "checkout -" after a rebaseRamkumar Ramachandra, Jun 18, 2013
  5. 4/7 status: do not depend on rebase reflog messagesRamkumar Ramachandra, Jun 18, 2013
  6. 5/7 checkout: respect GIT_REFLOG_ACTIONRamkumar Ramachandra, Jun 18, 2013
  7. 6/7 rebase: write better reflog messagesRamkumar Ramachandra, Jun 18, 2013
  8. Junio C HamanoJun 18, 2013
  9. Johannes SixtJun 19, 2013
  10. Ramkumar RamachandraJun 19, 2013
  11. Johannes SixtJun 19, 2013
  12. Junio C HamanoJun 19, 2013
  13. Junio C HamanoJun 19, 2013
  14. Junio C HamanoJun 19, 2013
  15. 7/7 rebase -i: write better reflog messagesRamkumar Ramachandra, Jun 18, 2013
  16. Junio C HamanoJun 18, 2013
  17. Ramkumar RamachandraJun 18, 2013
  18. Junio C HamanoJun 18, 2013
  19. Ramkumar RamachandraJun 19, 2013

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.