summaryrefslogtreecommitdiff
path: root/builtin-commit.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2010-01-13 17:39:51 (GMT)
committerJunio C Hamano <gitster@pobox.com>2010-01-14 17:25:28 (GMT)
commit49ff9a7a02266a1b96e2236bc8f8d95e4b9507dd (patch)
treed21218dfd8ac9127362170ab6ddf6feb7bc0db4c /builtin-commit.c
parent361df5df77255321b2ca409d892b4c24b7b0441d (diff)
downloadgit-49ff9a7a02266a1b96e2236bc8f8d95e4b9507dd.zip
git-49ff9a7a02266a1b96e2236bc8f8d95e4b9507dd.tar.gz
git-49ff9a7a02266a1b96e2236bc8f8d95e4b9507dd.tar.bz2
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>
Diffstat (limited to 'builtin-commit.c')
-rw-r--r--builtin-commit.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/builtin-commit.c b/builtin-commit.c
index f54772f..b923038 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -35,7 +35,20 @@ static const char * const builtin_status_usage[] = {
NULL
};
+static const char implicit_ident_advice[] =
+"Your name and email address were configured automatically based\n"
+"on your username and hostname. Please check that they are accurate.\n"
+"You can suppress this message by setting them explicitly:\n"
+"\n"
+" git config --global user.name Your Name\n"
+" git config --global user.email you@example.com\n"
+"\n"
+"If the identity used for this commit is wrong, you can fix it with:\n"
+"\n"
+" git commit --amend --author='Your Name <you@example.com>'\n";
+
static unsigned char head_sha1[20], merge_head_sha1[20];
+
static char *use_message_buffer;
static const char commit_editmsg[] = "COMMIT_EDITMSG";
static struct lock_file index_lock; /* real index */
@@ -957,9 +970,12 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
{
struct rev_info rev;
struct commit *commit;
- static const char *format = "format:%h] %s";
+ struct strbuf format = STRBUF_INIT;
unsigned char junk_sha1[20];
const char *head = resolve_ref("HEAD", junk_sha1, 0, NULL);
+ struct pretty_print_context pctx = {0};
+ struct strbuf author_ident = STRBUF_INIT;
+ struct strbuf committer_ident = STRBUF_INIT;
commit = lookup_commit(sha1);
if (!commit)
@@ -967,6 +983,23 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
if (!commit || parse_commit(commit))
die("could not parse newly created commit");
+ strbuf_addstr(&format, "format:%h] %s");
+
+ format_commit_message(commit, "%an <%ae>", &author_ident, &pctx);
+ format_commit_message(commit, "%cn <%ce>", &committer_ident, &pctx);
+ if (strbuf_cmp(&author_ident, &committer_ident)) {
+ strbuf_addstr(&format, "\n Author: ");
+ strbuf_addbuf_percentquote(&format, &author_ident);
+ }
+ if (!user_ident_explicitly_given) {
+ strbuf_addstr(&format, "\n Committer: ");
+ strbuf_addbuf_percentquote(&format, &committer_ident);
+ strbuf_addch(&format, '\n');
+ strbuf_addstr(&format, implicit_ident_advice);
+ }
+ strbuf_release(&author_ident);
+ strbuf_release(&committer_ident);
+
init_revisions(&rev, prefix);
setup_revisions(0, NULL, &rev, NULL);
@@ -977,7 +1010,8 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
rev.verbose_header = 1;
rev.show_root_diff = 1;
- get_commit_format(format, &rev);
+ get_commit_format(format.buf, &rev);
+ strbuf_release(&format);
rev.always_show_header = 0;
rev.diffopt.detect_rename = 1;
rev.diffopt.rename_limit = 100;
@@ -996,7 +1030,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
struct pretty_print_context ctx = {0};
struct strbuf buf = STRBUF_INIT;
ctx.date_mode = DATE_NORMAL;
- format_commit_message(commit, format + 7, &buf, &ctx);
+ format_commit_message(commit, format.buf + 7, &buf, &ctx);
printf("%s\n", buf.buf);
strbuf_release(&buf);
}