@matheusbsbs / matheus-bagliano / commits / 643cb5f7c9
Fork 0

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 (f5bbc3225c4b073a7ff3218164a0c820299bc9c6, 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 <chriscool@tuxfamily.org> Acked-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Jun 12, 2010 at 18:05 UTC 643cb5f7c99e77a4a3e97213dd226a7dc2650c02
2 files changed +13 -6
builtin/commit.c
+9 -4
@@ -1232,13 +1232,16 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1232 }
1233
1234 /* Determine parents */
1235 + reflog_msg = getenv("GIT_REFLOG_ACTION");
1236 if (initial_commit) {
1236 - reflog_msg = "commit (initial)";
1237 + if (!reflog_msg)
1238 + reflog_msg = "commit (initial)";
1239 } else if (amend) {
1240 struct commit_list *c;
1241 struct commit *commit;
1242
1241 - reflog_msg = "commit (amend)";
1243 + if (!reflog_msg)
1244 + reflog_msg = "commit (amend)";
1245 commit = lookup_commit(head_sha1);
1246 if (!commit || parse_commit(commit))
1247 die("could not parse HEAD commit");
@@ -1249,7 +1252,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1252 struct strbuf m = STRBUF_INIT;
1253 FILE *fp;
1254
1252 - reflog_msg = "commit (merge)";
1255 + if (!reflog_msg)
1256 + reflog_msg = "commit (merge)";
1257 pptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next;
1258 fp = fopen(git_path("MERGE_HEAD"), "r");
1259 if (fp == NULL)
@@ -1272,7 +1276,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1276 if (allow_fast_forward)
1277 parents = reduce_heads(parents);
1278 } else {
1275 - reflog_msg = "commit";
1279 + if (!reflog_msg)
1280 + reflog_msg = "commit";
1281 pptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next;
1282 }
1283
t/t3501-revert-cherry-pick.sh
+4 -2
@@ -47,7 +47,8 @@ test_expect_success 'cherry-pick after renaming branch' '
47 git cherry-pick added &&
48 test $(git rev-parse HEAD^) = $(git rev-parse rename2) &&
49 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
52
53 '
54
@@ -57,7 +58,8 @@ test_expect_success 'revert after renaming branch' '
58 git revert added &&
59 test $(git rev-parse HEAD^) = $(git rev-parse rename1) &&
60 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
63
64 '
65