]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4212-log-corrupt.sh
Merge branch 'jk/bundle-progress'
[thirdparty/git.git] / t / t4212-log-corrupt.sh
1 #!/bin/sh
2
3 test_description='git log with invalid commit headers'
4
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_expect_success 'setup' '
9 test_commit foo &&
10
11 git cat-file commit HEAD |
12 sed "/^author /s/>/>-<>/" >broken_email.commit &&
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
17 test_expect_success 'fsck notices broken commit' '
18 test_must_fail git fsck 2>actual &&
19 test_i18ngrep invalid.author actual
20 '
21
22 test_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
37 test_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
46 munge_author_date () {
47 git cat-file commit "$1" >commit.orig &&
48 sed "s/^\(author .*>\) [0-9]*/\1 $2/" <commit.orig >commit.munge &&
49 git hash-object --literally -w -t commit commit.munge
50 }
51
52 test_expect_success 'unparsable dates produce sentinel value' '
53 commit=$(munge_author_date HEAD totally_bogus) &&
54 echo "Date: Thu Jan 1 00:00:00 1970 +0000" >expect &&
55 git log -1 $commit >actual.full &&
56 grep Date <actual.full >actual &&
57 test_cmp expect actual
58 '
59
60 test_expect_success 'unparsable dates produce sentinel value (%ad)' '
61 commit=$(munge_author_date HEAD totally_bogus) &&
62 echo >expect &&
63 git log -1 --format=%ad $commit >actual &&
64 test_cmp expect actual
65 '
66
67 # date is 2^64 + 1
68 test_expect_success 'date parser recognizes integer overflow' '
69 commit=$(munge_author_date HEAD 18446744073709551617) &&
70 echo "Thu Jan 1 00:00:00 1970 +0000" >expect &&
71 git log -1 --format=%ad $commit >actual &&
72 test_cmp expect actual
73 '
74
75 # date is 2^64 - 2
76 test_expect_success 'date parser recognizes time_t overflow' '
77 commit=$(munge_author_date HEAD 18446744073709551614) &&
78 echo "Thu Jan 1 00:00:00 1970 +0000" >expect &&
79 git log -1 --format=%ad $commit >actual &&
80 test_cmp expect actual
81 '
82
83 # date is within 2^63-1, but enough to choke glibc's gmtime
84 test_expect_success 'absurdly far-in-future date' '
85 commit=$(munge_author_date HEAD 999999999999999999) &&
86 git log -1 --format=%ad $commit
87 '
88
89 test_done