Skip to content

Commit e83dbe8

Browse files
sbejargitster
authored andcommitted
commit: Show author if different from committer
That would help reassure anybody while committing other's changes. Signed-off-by: Santi Béjar <sbejar@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent a45d46b commit e83dbe8

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

builtin-commit.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static enum {
4747

4848
static char *logfile, *force_author, *template_file;
4949
static char *edit_message, *use_message;
50+
static char *author_name, *author_email, *author_date;
5051
static int all, edit_flag, also, interactive, only, amend, signoff;
5152
static int quiet, verbose, untracked_files, no_verify, allow_empty;
5253
/*
@@ -395,7 +396,7 @@ static int is_a_merge(const unsigned char *sha1)
395396

396397
static const char sign_off_header[] = "Signed-off-by: ";
397398

398-
static void determine_author_info(struct strbuf *sb)
399+
static void determine_author_info(void)
399400
{
400401
char *name, *email, *date;
401402

@@ -431,7 +432,9 @@ static void determine_author_info(struct strbuf *sb)
431432
email = xstrndup(lb + 2, rb - (lb + 2));
432433
}
433434

434-
strbuf_addf(sb, "author %s\n", fmt_ident(name, email, date, IDENT_ERROR_ON_NO_NAME));
435+
author_name = name;
436+
author_email = email;
437+
author_date = date;
435438
}
436439

437440
static int prepare_to_commit(const char *index_file, const char *prefix)
@@ -522,7 +525,12 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
522525

523526
strbuf_release(&sb);
524527

528+
determine_author_info();
529+
525530
if (use_editor) {
531+
char *author_ident;
532+
const char *committer_ident;
533+
526534
if (in_merge)
527535
fprintf(fp,
528536
"#\n"
@@ -545,6 +553,17 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
545553
if (only_include_assumed)
546554
fprintf(fp, "# %s\n", only_include_assumed);
547555

556+
author_ident = xstrdup(fmt_name(author_name, author_email));
557+
committer_ident = fmt_name(getenv("GIT_COMMITTER_NAME"),
558+
getenv("GIT_COMMITTER_EMAIL"));
559+
if (strcmp(author_ident, committer_ident))
560+
fprintf(fp,
561+
"#\n"
562+
"# Author: %s\n"
563+
"#\n",
564+
author_ident);
565+
free(author_ident);
566+
548567
saved_color_setting = wt_status_use_color;
549568
wt_status_use_color = 0;
550569
commitable = run_status(fp, index_file, prefix, 1);
@@ -920,7 +939,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
920939
strbuf_addf(&sb, "parent %s\n", sha1_to_hex(head_sha1));
921940
}
922941

923-
determine_author_info(&sb);
942+
strbuf_addf(&sb, "author %s\n",
943+
fmt_ident(author_name, author_email, author_date, IDENT_ERROR_ON_NO_NAME));
924944
strbuf_addf(&sb, "committer %s\n", git_committer_info(IDENT_ERROR_ON_NO_NAME));
925945
if (!is_encoding_utf8(git_commit_encoding))
926946
strbuf_addf(&sb, "encoding %s\n", git_commit_encoding);

t/t7502-commit.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,18 @@ test_expect_success 'cleanup commit messages (strip,-F,-e)' '
154154
155155
'
156156

157+
echo "#
158+
# Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
159+
#" >> expect
160+
161+
test_expect_success 'author different from committer' '
162+
163+
echo >>negative &&
164+
git commit -e -m "sample"
165+
head -n 7 .git/COMMIT_EDITMSG >actual &&
166+
test_cmp expect actual
167+
'
168+
157169
pwd=`pwd`
158170
cat >> .git/FAKE_EDITOR << EOF
159171
#! /bin/sh

0 commit comments

Comments
 (0)