Merge branch 'jk/warn-author-committer-after-commit'
* jk/warn-author-committer-after-commit: user_ident_sufficiently_given(): refactor the logic to be usable from elsewhere commit.c::print_summary: do not release the format string too early commit: allow suppression of implicit identity advice commit: show interesting ident information in summary strbuf: add strbuf_addbuf_percentquote strbuf_expand: convert "%%" to "%" Conflicts: builtin-commit.c ident.c
This commit is contained in:
@ -36,7 +36,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];
|
||||
|
||||
static char *use_message_buffer;
|
||||
static const char commit_editmsg[] = "COMMIT_EDITMSG";
|
||||
static struct lock_file index_lock; /* real index */
|
||||
@ -1055,9 +1068,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)
|
||||
@ -1065,6 +1081,25 @@ 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_sufficiently_given()) {
|
||||
strbuf_addstr(&format, "\n Committer: ");
|
||||
strbuf_addbuf_percentquote(&format, &committer_ident);
|
||||
if (advice_implicit_identity) {
|
||||
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);
|
||||
|
||||
@ -1075,7 +1110,7 @@ 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);
|
||||
rev.always_show_header = 0;
|
||||
rev.diffopt.detect_rename = 1;
|
||||
rev.diffopt.rename_limit = 100;
|
||||
@ -1094,10 +1129,11 @@ 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);
|
||||
}
|
||||
strbuf_release(&format);
|
||||
}
|
||||
|
||||
static int git_commit_config(const char *k, const char *v, void *cb)
|
||||
|
||||
Reference in New Issue
Block a user