summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2014-05-01 21:10:01 -0400
committerJunio C Hamano <gitster@pobox.com>2014-05-02 14:14:21 -0700
commitb7242b8c9e4b3c57a07c2a76d0337389605aadcc (patch)
tree34772e47e05d428e7608ee04f5922ff56f4c1539 /builtin
parentd1053246554d176173893a5283dc0c0fb563ed03 (diff)
downloadgit-b7242b8c9e4b3c57a07c2a76d0337389605aadcc.tar.gz
commit: print "Date" line when the user has set date
When we make a commit and the author is not the same as the committer (e.g., because you used "-c $commit" or "--author=$somebody"), we print the author's name and email in both the commit-message template and as part of the commit summary. This is a safety check to give the user a chance to confirm that we are doing what they expect. This patch brings the same safety for the "date" field, which may be set by "-c" or by using "--date". Note that we explicitly do not set it for $GIT_AUTHOR_DATE, as it is probably not of interest when "git commit" is being fed its parameters by a script. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/commit.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/builtin/commit.c b/builtin/commit.c
index 728cc9bbfc..a25661f343 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -592,6 +592,11 @@ static void split_ident_or_die(struct ident_split *id, const struct strbuf *buf)
die(_("Malformed ident string: '%s'"), buf->buf);
}
+static int author_date_is_interesting(void)
+{
+ return author_message || force_date;
+}
+
static int prepare_to_commit(const char *index_file, const char *prefix,
struct commit *current_head,
struct wt_status *s,
@@ -805,6 +810,13 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
(int)(ai.name_end - ai.name_begin), ai.name_begin,
(int)(ai.mail_end - ai.mail_begin), ai.mail_begin);
+ if (author_date_is_interesting())
+ status_printf_ln(s, GIT_COLOR_NORMAL,
+ _("%s"
+ "Date: %s"),
+ ident_shown++ ? "" : "\n",
+ show_ident_date(&ai, DATE_NORMAL));
+
if (!committer_ident_sufficiently_given())
status_printf_ln(s, GIT_COLOR_NORMAL,
_("%s"
@@ -1355,6 +1367,13 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
strbuf_addstr(&format, "\n Author: ");
strbuf_addbuf_percentquote(&format, &author_ident);
}
+ if (author_date_is_interesting()) {
+ struct strbuf date = STRBUF_INIT;
+ format_commit_message(commit, "%ad", &date, &pctx);
+ strbuf_addstr(&format, "\n Date: ");
+ strbuf_addbuf_percentquote(&format, &date);
+ strbuf_release(&date);
+ }
if (!committer_ident_sufficiently_given()) {
strbuf_addstr(&format, "\n Committer: ");
strbuf_addbuf_percentquote(&format, &committer_ident);