builtin-commit: add --date option
This is like --author: allow a user to specify a given date without using the GIT_AUTHOR_DATE environment variable. Signed-off-by: Miklos Vajna <vmiklos@frugalware.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Miklos Vajna committed
Dec 2, 2009 at 23:16 UTC
02b47cd77e4af40da95a74c90846965a2ea6999b
3 files changed
+24
-2
Documentation/git-commit.txt
+4
-1
@@ -11,7 +11,7 @@ SYNOPSIS
11
'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run]
12
[(-c | -C) <commit>] [-F <file> | -m <msg>] [--reset-author]
13
[--allow-empty] [--no-verify] [-e] [--author=<author>]
14
- [--cleanup=<mode>] [--] [[-i | -o ]<file>...]
14
+ [--date=<date>] [--cleanup=<mode>] [--] [[-i | -o ]<file>...]
15
16
DESCRIPTION
17
-----------
@@ -85,6 +85,9 @@ OPTIONS
85
an existing commit that matches the given string and its author
86
name is used.
87
88
+--date=<date>::
89
+ Override the author date used in the commit.
90
+
91
-m <msg>::
92
--message=<msg>::
93
Use the given <msg> as the commit message.
builtin-commit.c
+5
-1
@@ -52,7 +52,7 @@ static char *edit_message, *use_message;
52
static char *author_name, *author_email, *author_date;
53
static int all, edit_flag, also, interactive, only, amend, signoff;
54
static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
55
-static char *untracked_files_arg;
55
+static char *untracked_files_arg, *force_date;
56
/*
57
* The default commit message cleanup mode will remove the lines
58
* beginning with # (shell comments) and leading and trailing
@@ -90,6 +90,7 @@ static struct option builtin_commit_options[] = {
90
91
OPT_FILENAME('F', "file", &logfile, "read log from file"),
92
OPT_STRING(0, "author", &force_author, "AUTHOR", "override author for commit"),
93
+ OPT_STRING(0, "date", &force_date, "DATE", "override date for commit"),
94
OPT_CALLBACK('m', "message", &message, "MESSAGE", "specify commit message", opt_parse_m),
95
OPT_STRING('c', "reedit-message", &edit_message, "COMMIT", "reuse and edit message from specified commit"),
96
OPT_STRING('C', "reuse-message", &use_message, "COMMIT", "reuse message from specified commit"),
@@ -410,6 +411,9 @@ static void determine_author_info(void)
411
email = xstrndup(lb + 2, rb - (lb + 2));
412
}
413
414
+ if (force_date)
415
+ date = force_date;
416
+
417
author_name = name;
418
author_email = email;
419
author_date = date;
t/t7501-commit.sh
+15
@@ -211,6 +211,21 @@ test_expect_success 'amend commit to fix author' '
211
212
'
213
214
+test_expect_success 'amend commit to fix date' '
215
+
216
+ test_tick &&
217
+ newtick=$GIT_AUTHOR_DATE &&
218
+ git reset --hard &&
219
+ git cat-file -p HEAD |
220
+ sed -e "s/author.*/author $author $newtick/" \
221
+ -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
222
+ expected &&
223
+ git commit --amend --date="$newtick" &&
224
+ git cat-file -p HEAD > current &&
225
+ test_cmp expected current
226
+
227
+'
228
+
229
test_expect_success 'sign off (1)' '
230
231
echo 1 >positive &&