Skip to content

Commit 643cb5f

Browse files
chriscoolgitster
authored andcommitted
commit: use value of GIT_REFLOG_ACTION env variable as reflog message
The environment variable GIT_REFLOG_ACTION was used by git-commit.sh, but when it was converted to a builtin (f5bbc32, Port git commit to C, Nov 8 2007) this was lost. Let's use it again as it is more user friendly when reverting or cherry-picking to see "revert" or "cherry-pick" in the reflog rather than to just see "commit". Signed-off-by: Christian Couder <[email protected]> Acked-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0d4dbcd commit 643cb5f

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

builtin/commit.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,13 +1232,16 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
12321232
}
12331233

12341234
/* Determine parents */
1235+
reflog_msg = getenv("GIT_REFLOG_ACTION");
12351236
if (initial_commit) {
1236-
reflog_msg = "commit (initial)";
1237+
if (!reflog_msg)
1238+
reflog_msg = "commit (initial)";
12371239
} else if (amend) {
12381240
struct commit_list *c;
12391241
struct commit *commit;
12401242

1241-
reflog_msg = "commit (amend)";
1243+
if (!reflog_msg)
1244+
reflog_msg = "commit (amend)";
12421245
commit = lookup_commit(head_sha1);
12431246
if (!commit || parse_commit(commit))
12441247
die("could not parse HEAD commit");
@@ -1249,7 +1252,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
12491252
struct strbuf m = STRBUF_INIT;
12501253
FILE *fp;
12511254

1252-
reflog_msg = "commit (merge)";
1255+
if (!reflog_msg)
1256+
reflog_msg = "commit (merge)";
12531257
pptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next;
12541258
fp = fopen(git_path("MERGE_HEAD"), "r");
12551259
if (fp == NULL)
@@ -1272,7 +1276,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
12721276
if (allow_fast_forward)
12731277
parents = reduce_heads(parents);
12741278
} else {
1275-
reflog_msg = "commit";
1279+
if (!reflog_msg)
1280+
reflog_msg = "commit";
12761281
pptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next;
12771282
}
12781283

t/t3501-revert-cherry-pick.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ test_expect_success 'cherry-pick after renaming branch' '
4747
git cherry-pick added &&
4848
test $(git rev-parse HEAD^) = $(git rev-parse rename2) &&
4949
test -f opos &&
50-
grep "Add extra line at the end" opos
50+
grep "Add extra line at the end" opos &&
51+
git reflog -1 | grep cherry-pick
5152
5253
'
5354

@@ -57,7 +58,8 @@ test_expect_success 'revert after renaming branch' '
5758
git revert added &&
5859
test $(git rev-parse HEAD^) = $(git rev-parse rename1) &&
5960
test -f spoo &&
60-
! grep "Add extra line at the end" spoo
61+
! grep "Add extra line at the end" spoo &&
62+
git reflog -1 | grep revert
6163
6264
'
6365

0 commit comments

Comments
 (0)