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

[PATCH 5/8] checkout: respect GIT_REFLOG_ACTION

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
Jun 18, 2013, 12:14 UTC
Message-ID
<1371557670-12534-6-git-send-email-artagnon@gmail.com>
In-Reply-To
<1371557670-12534-1-git-send-email-artagnon@gmail.com>

GIT_REFLOG_ACTION is an environment variable specifying the reflog message to write after an action is completed. Several other commands including merge, reset, and commit respect it.

Fix the failing tests in t/checkout-last by making checkout respect it too. You can now expect

  $ git checkout -

to work as expected after any a rebase [-i]. It will also work with any other scripts provided they set an appropriate GIT_REFLOG_ACTION if they internally use "git checkout".

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/checkout.c       | 11 ++++++++---
 t/t2012-checkout-last.sh |  8 ++++----
 2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/builtin/checkout.c b/builtin/checkout.c
index f5b50e5..1e2af85 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -587,7 +587,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
 				   struct branch_info *new)
 {
 	struct strbuf msg = STRBUF_INIT;
-	const char *old_desc;
+	const char *old_desc, *reflog_msg;
 	if (opts->new_branch) {
 		if (opts->new_orphan_branch) {
 			if (opts->new_branch_log && !log_all_ref_updates) {
@@ -620,8 +620,13 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
 	old_desc = old->name;
 	if (!old_desc && old->commit)
 		old_desc = sha1_to_hex(old->commit->object.sha1);
-	strbuf_addf(&msg, "checkout: moving from %s to %s",
-		    old_desc ? old_desc : "(invalid)", new->name);
+
+	reflog_msg = getenv("GIT_REFLOG_ACTION");
+	if (!reflog_msg)
+		strbuf_addf(&msg, "checkout: moving from %s to %s",
+			old_desc ? old_desc : "(invalid)", new->name);
+	else
+		strbuf_insert(&msg, 0, reflog_msg, strlen(reflog_msg));
 
 	if (!strcmp(new->name, "HEAD") && !new->path && !opts->force_detach) {
 		/* Nothing to do. */
diff --git a/t/t2012-checkout-last.sh b/t/t2012-checkout-last.sh
index 6ad6edf..e7ba8c5 100755
--- a/t/t2012-checkout-last.sh
+++ b/t/t2012-checkout-last.sh
@@ -116,7 +116,7 @@ test_expect_success 'master...' '
 	test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify master^)"
 '
 
-test_expect_failure '"checkout -" works after a rebase A' '
+test_expect_success '"checkout -" works after a rebase A' '
 	git checkout master &&
 	git checkout other &&
 	git rebase master &&
@@ -124,7 +124,7 @@ test_expect_failure '"checkout -" works after a rebase A' '
 	test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
 '
 
-test_expect_failure '"checkout -" works after a rebase A B' '
+test_expect_success '"checkout -" works after a rebase A B' '
 	git branch moodle master~1 &&
 	git checkout master &&
 	git checkout other &&
@@ -133,7 +133,7 @@ test_expect_failure '"checkout -" works after a rebase A B' '
 	test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
 '
 
-test_expect_failure '"checkout -" works after a rebase -i A' '
+test_expect_success '"checkout -" works after a rebase -i A' '
 	git checkout master &&
 	git checkout other &&
 	git rebase -i master &&
@@ -141,7 +141,7 @@ test_expect_failure '"checkout -" works after a rebase -i A' '
 	test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
 '
 
-test_expect_failure '"checkout -" works after a rebase -i A B' '
+test_expect_success '"checkout -" works after a rebase -i A B' '
 	git branch foodle master~1 &&
 	git checkout master &&
 	git checkout other &&
-- 
1.8.3.1.456.gb7f4cb6
Previous: Peter KreftingNext: Junio C Hamano
Message 7 of 15 in “Re-roll rr/rebase-checkout-reflog”
  1. 0/8 Re-roll rr/rebase-checkout-reflogRamkumar Ramachandra, Jun 18, 2013
  2. 1/8 t/status-help: test "HEAD detached from"Ramkumar Ramachandra, Jun 18, 2013
  3. 2/8 wt-status: remove unused field in grab_1st_switch_cbdataRamkumar Ramachandra, Jun 18, 2013
  4. 3/8 t/checkout-last: test "checkout -" after a rebaseRamkumar Ramachandra, Jun 18, 2013
  5. 4/8 status: do not depend on rebase reflog messagesRamkumar Ramachandra, Jun 18, 2013
  6. Peter KreftingJun 18, 2013
  7. 5/8 checkout: respect GIT_REFLOG_ACTIONRamkumar Ramachandra, Jun 18, 2013
  8. Junio C HamanoJun 18, 2013
  9. Ramkumar RamachandraJun 18, 2013
  10. 6/8 sh-setup: make die_with_status clear GIT_REFLOG_ACTIONRamkumar Ramachandra, Jun 18, 2013
  11. Junio C HamanoJun 18, 2013
  12. Ramkumar RamachandraJun 18, 2013
  13. Junio C HamanoJun 18, 2013
  14. 7/8 rebase: write better reflog messagesRamkumar Ramachandra, Jun 18, 2013
  15. 8/8 rebase -i: write better reflog messagesRamkumar Ramachandra, Jun 18, 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.