interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t4212-log-corrupt.sh

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