Skip to content

Commit 3bed291

Browse files
artagnongitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ec50631 commit 3bed291

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

builtin/checkout.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
587587
struct branch_info *new)
588588
{
589589
struct strbuf msg = STRBUF_INIT;
590-
const char *old_desc;
590+
const char *old_desc, *reflog_msg;
591591
if (opts->new_branch) {
592592
if (opts->new_orphan_branch) {
593593
if (opts->new_branch_log && !log_all_ref_updates) {
@@ -620,8 +620,13 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
620620
old_desc = old->name;
621621
if (!old_desc && old->commit)
622622
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));
625630

626631
if (!strcmp(new->name, "HEAD") && !new->path && !opts->force_detach) {
627632
/* Nothing to do. */

t/t2012-checkout-last.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ test_expect_success 'master...' '
116116
test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify master^)"
117117
'
118118

119-
test_expect_failure '"checkout -" works after a rebase A' '
119+
test_expect_success '"checkout -" works after a rebase A' '
120120
git checkout master &&
121121
git checkout other &&
122122
git rebase master &&
123123
git checkout - &&
124124
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
125125
'
126126

127-
test_expect_failure '"checkout -" works after a rebase A B' '
127+
test_expect_success '"checkout -" works after a rebase A B' '
128128
git branch moodle master~1 &&
129129
git checkout master &&
130130
git checkout other &&
@@ -133,15 +133,15 @@ test_expect_failure '"checkout -" works after a rebase A B' '
133133
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
134134
'
135135

136-
test_expect_failure '"checkout -" works after a rebase -i A' '
136+
test_expect_success '"checkout -" works after a rebase -i A' '
137137
git checkout master &&
138138
git checkout other &&
139139
git rebase -i master &&
140140
git checkout - &&
141141
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
142142
'
143143

144-
test_expect_failure '"checkout -" works after a rebase -i A B' '
144+
test_expect_success '"checkout -" works after a rebase -i A B' '
145145
git branch foodle master~1 &&
146146
git checkout master &&
147147
git checkout other &&

0 commit comments

Comments
 (0)