@matheusbsbs / matheus-bagliano / commits / 4579bb418c
Fork 0

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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Dec 13, 2010 at 12:02 UTC 4579bb418c2995a8459de7dba42b63a26006f9a6
2 files changed +8 -2
ident.c
+4 -2
@@ -217,8 +217,10 @@ const char *fmt_ident(const char *name, const char *email,
217 }
218
219 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 + }
224
225 i = copy(buffer, sizeof(buffer), 0, name);
226 i = add_raw(buffer, sizeof(buffer), i, " <");
t/t7501-commit.sh
+4
@@ -230,6 +230,10 @@ test_expect_success 'amend commit to fix date' '
230
231 '
232
233 +test_expect_success 'commit complains about bogus date' '
234 + test_must_fail git commit --amend --date=10.11.2010
235 +'
236 +
237 test_expect_success 'sign off (1)' '
238
239 echo 1 >positive &&