Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 7d9a281

Browse files
peffgitster
authored andcommitted
t4212: test bogus timestamps with git-log
When t4212 was originally added by 9dbe7c3 (pretty: handle broken commit headers gracefully, 2013-04-17), it tested our handling of commits with broken ident lines in which the timestamps could not be parsed. It does so using a bogus line like "Name <email>-<> 1234 -0000", because that simulates an error that was seen in the wild. Later, 03818a4 (split_ident: parse timestamp from end of line, 2013-10-14) made our parser smart enough to actually find the timestamp on such a line, and t4212 was adjusted to match. While it's nice that we handle this real-world case, this meant that we were not actually testing the bogus-timestamp case anymore. This patch adds a test with a totally incomprehensible timestamp to make sure we are testing the code path. Note that the behavior is slightly different between regular log output and "--format=%ad". In the former case, we produce a sentinel value and in the latter, we produce an empty string. While at first this seems unnecessarily inconsistent, it matches the original behavior given by 9dbe7c3. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e45bda8 commit 7d9a281

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

t/t4212-log-corrupt.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,25 @@ test_expect_success 'git log --format with broken author email' '
3939
test_cmp expect.err actual.err
4040
'
4141

42+
munge_author_date () {
43+
git cat-file commit "$1" >commit.orig &&
44+
sed "s/^\(author .*>\) [0-9]*/\1 $2/" <commit.orig >commit.munge &&
45+
git hash-object -w -t commit commit.munge
46+
}
47+
48+
test_expect_success 'unparsable dates produce sentinel value' '
49+
commit=$(munge_author_date HEAD totally_bogus) &&
50+
echo "Date: Thu Jan 1 00:00:00 1970 +0000" >expect &&
51+
git log -1 $commit >actual.full &&
52+
grep Date <actual.full >actual &&
53+
test_cmp expect actual
54+
'
55+
56+
test_expect_success 'unparsable dates produce sentinel value (%ad)' '
57+
commit=$(munge_author_date HEAD totally_bogus) &&
58+
echo >expect &&
59+
git log -1 --format=%ad $commit >actual
60+
test_cmp expect actual
61+
'
62+
4263
test_done

0 commit comments

Comments
 (0)