@matheusbsbs / matheus-bagliano / commits / 49ff9a7a02
Fork 0

commit: show interesting ident information in summary

There are a few cases of user identity information that we consider interesting: (1) When the author and committer identities do not match. (2) When the committer identity was picked automatically from the username, hostname and GECOS information. In these cases, we already show the information in the commit message template. However, users do not always see that template because they might use "-m" or "-F". With this patch, we show these interesting cases after the commit, along with the subject and change summary. The new output looks like: $ git commit \ -m "federalist papers" \ --author='Publius <alexander@hamilton.com>' [master 3d226a7] federalist papers Author: Publius <alexander@hamilton.com> 1 files changed, 1 insertions(+), 0 deletions(-) for case (1), and: $ git config --global --unset user.name $ git config --global --unset user.email $ git commit -m foo [master 7c2a927] foo Committer: Jeff King <peff@c-71-185-130-222.hsd1.va.comcast.net> Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly: git config --global user.name Your Name git config --global user.email you@example.com If the identity used for this commit is wrong, you can fix it with: git commit --amend --author='Your Name <you@example.com>' 1 files changed, 1 insertions(+), 0 deletions(-) for case (2). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jan 13, 2010 at 12:39 UTC 49ff9a7a02266a1b96e2236bc8f8d95e4b9507dd
2 files changed +42 -4
builtin-commit.c
+37 -3
@@ -35,7 +35,20 @@ static const char * const builtin_status_usage[] = {
35 NULL
36 };
37
38 +static const char implicit_ident_advice[] =
39 +"Your name and email address were configured automatically based\n"
40 +"on your username and hostname. Please check that they are accurate.\n"
41 +"You can suppress this message by setting them explicitly:\n"
42 +"\n"
43 +" git config --global user.name Your Name\n"
44 +" git config --global user.email you@example.com\n"
45 +"\n"
46 +"If the identity used for this commit is wrong, you can fix it with:\n"
47 +"\n"
48 +" git commit --amend --author='Your Name <you@example.com>'\n";
49 +
50 static unsigned char head_sha1[20], merge_head_sha1[20];
51 +
52 static char *use_message_buffer;
53 static const char commit_editmsg[] = "COMMIT_EDITMSG";
54 static struct lock_file index_lock; /* real index */
@@ -957,9 +970,12 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
970 {
971 struct rev_info rev;
972 struct commit *commit;
960 - static const char *format = "format:%h] %s";
973 + struct strbuf format = STRBUF_INIT;
974 unsigned char junk_sha1[20];
975 const char *head = resolve_ref("HEAD", junk_sha1, 0, NULL);
976 + struct pretty_print_context pctx = {0};
977 + struct strbuf author_ident = STRBUF_INIT;
978 + struct strbuf committer_ident = STRBUF_INIT;
979
980 commit = lookup_commit(sha1);
981 if (!commit)
@@ -967,6 +983,23 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
983 if (!commit || parse_commit(commit))
984 die("could not parse newly created commit");
985
986 + strbuf_addstr(&format, "format:%h] %s");
987 +
988 + format_commit_message(commit, "%an <%ae>", &author_ident, &pctx);
989 + format_commit_message(commit, "%cn <%ce>", &committer_ident, &pctx);
990 + if (strbuf_cmp(&author_ident, &committer_ident)) {
991 + strbuf_addstr(&format, "\n Author: ");
992 + strbuf_addbuf_percentquote(&format, &author_ident);
993 + }
994 + if (!user_ident_explicitly_given) {
995 + strbuf_addstr(&format, "\n Committer: ");
996 + strbuf_addbuf_percentquote(&format, &committer_ident);
997 + strbuf_addch(&format, '\n');
998 + strbuf_addstr(&format, implicit_ident_advice);
999 + }
1000 + strbuf_release(&author_ident);
1001 + strbuf_release(&committer_ident);
1002 +
1003 init_revisions(&rev, prefix);
1004 setup_revisions(0, NULL, &rev, NULL);
1005
@@ -977,7 +1010,8 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
1010
1011 rev.verbose_header = 1;
1012 rev.show_root_diff = 1;
980 - get_commit_format(format, &rev);
1013 + get_commit_format(format.buf, &rev);
1014 + strbuf_release(&format);
1015 rev.always_show_header = 0;
1016 rev.diffopt.detect_rename = 1;
1017 rev.diffopt.rename_limit = 100;
@@ -996,7 +1030,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
1030 struct pretty_print_context ctx = {0};
1031 struct strbuf buf = STRBUF_INIT;
1032 ctx.date_mode = DATE_NORMAL;
999 - format_commit_message(commit, format + 7, &buf, &ctx);
1033 + format_commit_message(commit, format.buf + 7, &buf, &ctx);
1034 printf("%s\n", buf.buf);
1035 strbuf_release(&buf);
1036 }
t/t7501-commit.sh
+5 -1
@@ -117,7 +117,11 @@ test_expect_success \
117 test_expect_success \
118 "overriding author from command line" \
119 "echo 'gak' >file && \
120 - git commit -m 'author' --author 'Rubber Duck <rduck@convoy.org>' -a"
120 + git commit -m 'author' --author 'Rubber Duck <rduck@convoy.org>' -a >output 2>&1"
121 +
122 +test_expect_success \
123 + "commit --author output mentions author" \
124 + "grep Rubber.Duck output"
125
126 test_expect_success PERL \
127 "interactive add" \