@matheusbsbs / matheus-bagliano / commits / e83dbe802f
Fork 0

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>

Santi Béjar committed May 4, 2008 at 18:04 UTC e83dbe802f24e017f2e3889272a70793c064d984
2 files changed +35 -3
builtin-commit.c
+23 -3
@@ -47,6 +47,7 @@ static enum {
47
48 static char *logfile, *force_author, *template_file;
49 static char *edit_message, *use_message;
50 +static char *author_name, *author_email, *author_date;
51 static int all, edit_flag, also, interactive, only, amend, signoff;
52 static int quiet, verbose, untracked_files, no_verify, allow_empty;
53 /*
@@ -395,7 +396,7 @@ static int is_a_merge(const unsigned char *sha1)
396
397 static const char sign_off_header[] = "Signed-off-by: ";
398
398 -static void determine_author_info(struct strbuf *sb)
399 +static void determine_author_info(void)
400 {
401 char *name, *email, *date;
402
@@ -431,7 +432,9 @@ static void determine_author_info(struct strbuf *sb)
432 email = xstrndup(lb + 2, rb - (lb + 2));
433 }
434
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;
438 }
439
440 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)
525
526 strbuf_release(&sb);
527
528 + determine_author_info();
529 +
530 if (use_editor) {
531 + char *author_ident;
532 + const char *committer_ident;
533 +
534 if (in_merge)
535 fprintf(fp,
536 "#\n"
@@ -545,6 +553,17 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
553 if (only_include_assumed)
554 fprintf(fp, "# %s\n", only_include_assumed);
555
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 +
567 saved_color_setting = wt_status_use_color;
568 wt_status_use_color = 0;
569 commitable = run_status(fp, index_file, prefix, 1);
@@ -920,7 +939,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
939 strbuf_addf(&sb, "parent %s\n", sha1_to_hex(head_sha1));
940 }
941
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));
944 strbuf_addf(&sb, "committer %s\n", git_committer_info(IDENT_ERROR_ON_NO_NAME));
945 if (!is_encoding_utf8(git_commit_encoding))
946 strbuf_addf(&sb, "encoding %s\n", git_commit_encoding);
t/t7502-commit.sh
+12
@@ -154,6 +154,18 @@ test_expect_success 'cleanup commit messages (strip,-F,-e)' '
154
155 '
156
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 +
169 pwd=`pwd`
170 cat >> .git/FAKE_EDITOR << EOF
171 #! /bin/sh