]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4212-log-corrupt.sh
The third batch
[thirdparty/git.git] / t / t4212-log-corrupt.sh
CommitLineData
9dbe7c3d
RS
1#!/bin/sh
2
3test_description='git log with invalid commit headers'
4
7a98d9ab 5TEST_PASSES_SANITIZE_LEAK=true
9dbe7c3d
RS
6. ./test-lib.sh
7
8test_expect_success 'setup' '
9 test_commit foo &&
10
2063b86b 11 git cat-file commit HEAD >ok.commit &&
ea1615df 12 sed "s/>/>-<>/" <ok.commit >broken_email.commit &&
2063b86b 13
34959d80 14 git hash-object --literally -w -t commit broken_email.commit >broken_email.hash &&
9dbe7c3d
RS
15 git update-ref refs/heads/broken_email $(cat broken_email.hash)
16'
17
03818a4a 18test_expect_success 'fsck notices broken commit' '
2e770fe4 19 test_must_fail git fsck 2>actual &&
6789275d 20 test_grep invalid.author actual
03818a4a
JK
21'
22
9dbe7c3d
RS
23test_expect_success 'git log with broken author email' '
24 {
7abcbcb7
ES
25 echo commit $(cat broken_email.hash) &&
26 echo "Author: A U Thor <author@example.com>" &&
27 echo "Date: Thu Apr 7 15:13:13 2005 -0700" &&
28 echo &&
9dbe7c3d
RS
29 echo " foo"
30 } >expect.out &&
9dbe7c3d
RS
31
32 git log broken_email >actual.out 2>actual.err &&
33
34 test_cmp expect.out actual.out &&
1c5e94f4 35 test_must_be_empty actual.err
9dbe7c3d
RS
36'
37
38test_expect_success 'git log --format with broken author email' '
03818a4a 39 echo "A U Thor+author@example.com+Thu Apr 7 15:13:13 2005 -0700" >expect.out &&
9dbe7c3d
RS
40
41 git log --format="%an+%ae+%ad" broken_email >actual.out 2>actual.err &&
42
43 test_cmp expect.out actual.out &&
1c5e94f4 44 test_must_be_empty actual.err
9dbe7c3d
RS
45'
46
ea1615df
JK
47test_expect_success '--until handles broken email' '
48 git rev-list --until=1980-01-01 broken_email >actual &&
49 test_must_be_empty actual
50'
51
7d9a2819
JK
52munge_author_date () {
53 git cat-file commit "$1" >commit.orig &&
54 sed "s/^\(author .*>\) [0-9]*/\1 $2/" <commit.orig >commit.munge &&
34959d80 55 git hash-object --literally -w -t commit commit.munge
7d9a2819
JK
56}
57
58test_expect_success 'unparsable dates produce sentinel value' '
59 commit=$(munge_author_date HEAD totally_bogus) &&
60 echo "Date: Thu Jan 1 00:00:00 1970 +0000" >expect &&
61 git log -1 $commit >actual.full &&
62 grep Date <actual.full >actual &&
63 test_cmp expect actual
64'
65
66test_expect_success 'unparsable dates produce sentinel value (%ad)' '
67 commit=$(munge_author_date HEAD totally_bogus) &&
68 echo >expect &&
60687de5 69 git log -1 --format=%ad $commit >actual &&
7d9a2819
JK
70 test_cmp expect actual
71'
72
1dca155f
JK
73# date is 2^64 + 1
74test_expect_success 'date parser recognizes integer overflow' '
75 commit=$(munge_author_date HEAD 18446744073709551617) &&
76 echo "Thu Jan 1 00:00:00 1970 +0000" >expect &&
77 git log -1 --format=%ad $commit >actual &&
78 test_cmp expect actual
79'
80
81# date is 2^64 - 2
82test_expect_success 'date parser recognizes time_t overflow' '
83 commit=$(munge_author_date HEAD 18446744073709551614) &&
84 echo "Thu Jan 1 00:00:00 1970 +0000" >expect &&
85 git log -1 --format=%ad $commit >actual &&
86 test_cmp expect actual
87'
88
2b15846d 89# date is within 2^63-1, but enough to choke glibc's gmtime
f80d1f95 90test_expect_success 'absurdly far-in-future date' '
2b15846d 91 commit=$(munge_author_date HEAD 999999999999999999) &&
f80d1f95 92 git log -1 --format=%ad $commit
2b15846d
JK
93'
94
089d9adf
JK
95test_expect_success 'create commits with whitespace committer dates' '
96 # It is important that this subject line is numeric, since we want to
97 # be sure we are not confused by skipping whitespace and accidentally
98 # parsing the subject as a timestamp.
99 #
100 # Do not use munge_author_date here. Besides not hitting the committer
101 # line, it leaves the timezone intact, and we want nothing but
102 # whitespace.
103 #
104 # We will make two munged commits here. The first, ws_commit, will
105 # be purely spaces. The second contains a vertical tab, which is
106 # considered a space by strtoumax(), but not by our isspace().
107 test_commit 1234567890 &&
108 git cat-file commit HEAD >commit.orig &&
109 sed "s/>.*/> /" <commit.orig >commit.munge &&
110 ws_commit=$(git hash-object --literally -w -t commit commit.munge) &&
111 sed "s/>.*/> $(printf "\013")/" <commit.orig >commit.munge &&
112 vt_commit=$(git hash-object --literally -w -t commit commit.munge)
113'
114
115test_expect_success '--until treats whitespace date as sentinel' '
116 echo $ws_commit >expect &&
117 git rev-list --until=1980-01-01 $ws_commit >actual &&
118 test_cmp expect actual &&
119
120 echo $vt_commit >expect &&
121 git rev-list --until=1980-01-01 $vt_commit >actual &&
122 test_cmp expect actual
123'
124
125test_expect_success 'pretty-printer handles whitespace date' '
126 # as with the %ad test above, we will show these as the empty string,
127 # not the 1970 epoch date. This is intentional; see 7d9a281941 (t4212:
128 # test bogus timestamps with git-log, 2014-02-24) for more discussion.
129 echo : >expect &&
130 git log -1 --format="%at:%ct" $ws_commit >actual &&
131 test_cmp expect actual &&
132 git log -1 --format="%at:%ct" $vt_commit >actual &&
133 test_cmp expect actual
134'
135
9dbe7c3d 136test_done