clone_submodule: avoid using `access()` on directories
[git.git] / t / t4212-log-corrupt.sh
blob30a219894bb45f2655596fe02e8a7d001a35eabd
1 #!/bin/sh
3 test_description='git log with invalid commit headers'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_expect_success 'setup' '
9 test_commit foo &&
11 git cat-file commit HEAD |
12 sed "/^author /s/>/>-<>/" >broken_email.commit &&
13 git hash-object -w -t commit broken_email.commit >broken_email.hash &&
14 git update-ref refs/heads/broken_email $(cat broken_email.hash)
17 test_expect_success 'fsck notices broken commit' '
18 test_must_fail git fsck 2>actual &&
19 test_i18ngrep invalid.author actual
22 test_expect_success 'git log with broken author email' '
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 &&
31 git log broken_email >actual.out 2>actual.err &&
33 test_cmp expect.out actual.out &&
34 test_must_be_empty actual.err
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 &&
40 git log --format="%an+%ae+%ad" broken_email >actual.out 2>actual.err &&
42 test_cmp expect.out actual.out &&
43 test_must_be_empty actual.err
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 -w -t commit commit.munge
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
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
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
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
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
89 test_done