Skip to content

Commit 4579bb4

Browse files
peffgitster
authored andcommitted
ident: die on bogus date format
If the user gives "git commit --date=foobar", we silently ignore the --date flag. We should note the error. This patch puts the fix at the lowest level of fmt_ident, which means it also handles GIT_AUTHOR_DATE=foobar, as well. There are two down-sides to this approach: 1. Technically this breaks somebody doing something like "git commit --date=now", which happened to work because bogus data is the same as "now". Though we do explicitly handle the empty string, so anybody passing an empty variable through the environment will still work. If the error is too much, perhaps it can be downgraded to a warning? 2. The error checking happens _after_ the commit message is written, which can be annoying to the user. We can put explicit checks closer to the beginning of git-commit, but that feels a little hack-ish; suddenly git-commit has to care about how fmt_ident works. Maybe we could simply call fmt_ident earlier? Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 05bb5a2 commit 4579bb4

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

ident.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,10 @@ const char *fmt_ident(const char *name, const char *email,
217217
}
218218

219219
strcpy(date, git_default_date);
220-
if (!name_addr_only && date_str)
221-
parse_date(date_str, date, sizeof(date));
220+
if (!name_addr_only && date_str && date_str[0]) {
221+
if (parse_date(date_str, date, sizeof(date)) < 0)
222+
die("invalid date format: %s", date_str);
223+
}
222224

223225
i = copy(buffer, sizeof(buffer), 0, name);
224226
i = add_raw(buffer, sizeof(buffer), i, " <");

t/t7501-commit.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ test_expect_success 'amend commit to fix date' '
230230
231231
'
232232

233+
test_expect_success 'commit complains about bogus date' '
234+
test_must_fail git commit --amend --date=10.11.2010
235+
'
236+
233237
test_expect_success 'sign off (1)' '
234238
235239
echo 1 >positive &&

0 commit comments

Comments
 (0)