checkout: respect GIT_REFLOG_ACTION

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 operation that internally uses "checkout" as its implementation detail, e.g. "rebase". Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ramkumar Ramachandra committed Jun 16, 2013 at 14:15 UTC 3bed291a3b121408b4de83f4fa3cc0f1d98c676e
2 files changed +12 -7
builtin/checkout.c
+8 -3
@@ -587,7 +587,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
587 struct branch_info *new)
588 {
589 struct strbuf msg = STRBUF_INIT;
590 - const char *old_desc;
590 + const char *old_desc, *reflog_msg;
591 if (opts->new_branch) {
592 if (opts->new_orphan_branch) {
593 if (opts->new_branch_log && !log_all_ref_updates) {
@@ -620,8 +620,13 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
620 old_desc = old->name;
621 if (!old_desc && old->commit)
622 old_desc = sha1_to_hex(old->commit->object.sha1);
623 - strbuf_addf(&msg, "checkout: moving from %s to %s",
624 - old_desc ? old_desc : "(invalid)", new->name);
623 +
624 + reflog_msg = getenv("GIT_REFLOG_ACTION");
625 + if (!reflog_msg)
626 + strbuf_addf(&msg, "checkout: moving from %s to %s",
627 + old_desc ? old_desc : "(invalid)", new->name);
628 + else
629 + strbuf_insert(&msg, 0, reflog_msg, strlen(reflog_msg));
630
631 if (!strcmp(new->name, "HEAD") && !new->path && !opts->force_detach) {
632 /* Nothing to do. */
t/t2012-checkout-last.sh
+4 -4
@@ -116,7 +116,7 @@ test_expect_success 'master...' '
116 test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify master^)"
117 '
118
119 -test_expect_failure '"checkout -" works after a rebase A' '
119 +test_expect_success '"checkout -" works after a rebase A' '
120 git checkout master &&
121 git checkout other &&
122 git rebase master &&
@@ -124,7 +124,7 @@ test_expect_failure '"checkout -" works after a rebase A' '
124 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
125 '
126
127 -test_expect_failure '"checkout -" works after a rebase A B' '
127 +test_expect_success '"checkout -" works after a rebase A B' '
128 git branch moodle master~1 &&
129 git checkout master &&
130 git checkout other &&
@@ -133,7 +133,7 @@ test_expect_failure '"checkout -" works after a rebase A B' '
133 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
134 '
135
136 -test_expect_failure '"checkout -" works after a rebase -i A' '
136 +test_expect_success '"checkout -" works after a rebase -i A' '
137 git checkout master &&
138 git checkout other &&
139 git rebase -i master &&
@@ -141,7 +141,7 @@ test_expect_failure '"checkout -" works after a rebase -i A' '
141 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
142 '
143
144 -test_expect_failure '"checkout -" works after a rebase -i A B' '
144 +test_expect_success '"checkout -" works after a rebase -i A B' '
145 git branch foodle master~1 &&
146 git checkout master &&
147 git checkout other &&