use strpbrk(3) to search for characters from a given set
[git/debian.git] / t / t4212-log-corrupt.sh
blob03b952c90d2fca011038e38075344530b5d64477
1 #!/bin/sh
3 test_description='git log with invalid commit headers'
5 . ./test-lib.sh
7 test_expect_success 'setup' '
8 test_commit foo &&
10 git cat-file commit HEAD |
11 sed "/^author /s/>/>-<>/" >broken_email.commit &&
12 git hash-object -w -t commit broken_email.commit >broken_email.hash &&
13 git update-ref refs/heads/broken_email $(cat broken_email.hash)
16 test_expect_success 'fsck notices broken commit' '
17 test_must_fail git fsck 2>actual &&
18 test_i18ngrep invalid.author actual
21 test_expect_success 'git log with broken author email' '
23 echo commit $(cat broken_email.hash)
24 echo "Author: A U Thor <author@example.com>"
25 echo "Date: Thu Apr 7 15:13:13 2005 -0700"
26 echo
27 echo " foo"
28 } >expect.out &&
30 git log broken_email >actual.out 2>actual.err &&
32 test_cmp expect.out actual.out &&
33 test_must_be_empty actual.err
36 test_expect_success 'git log --format with broken author email' '
37 echo "A U Thor+author@example.com+Thu Apr 7 15:13:13 2005 -0700" >expect.out &&
39 git log --format="%an+%ae+%ad" broken_email >actual.out 2>actual.err &&
41 test_cmp expect.out actual.out &&
42 test_must_be_empty actual.err
45 munge_author_date () {
46 git cat-file commit "$1" >commit.orig &&
47 sed "s/^\(author .*>\) [0-9]*/\1 $2/" <commit.orig >commit.munge &&
48 git hash-object -w -t commit commit.munge
51 test_expect_success 'unparsable dates produce sentinel value' '
52 commit=$(munge_author_date HEAD totally_bogus) &&
53 echo "Date: Thu Jan 1 00:00:00 1970 +0000" >expect &&
54 git log -1 $commit >actual.full &&
55 grep Date <actual.full >actual &&
56 test_cmp expect actual
59 test_expect_success 'unparsable dates produce sentinel value (%ad)' '
60 commit=$(munge_author_date HEAD totally_bogus) &&
61 echo >expect &&
62 git log -1 --format=%ad $commit >actual &&
63 test_cmp expect actual
66 # date is 2^64 + 1
67 test_expect_success 'date parser recognizes integer overflow' '
68 commit=$(munge_author_date HEAD 18446744073709551617) &&
69 echo "Thu Jan 1 00:00:00 1970 +0000" >expect &&
70 git log -1 --format=%ad $commit >actual &&
71 test_cmp expect actual
74 # date is 2^64 - 2
75 test_expect_success 'date parser recognizes time_t overflow' '
76 commit=$(munge_author_date HEAD 18446744073709551614) &&
77 echo "Thu Jan 1 00:00:00 1970 +0000" >expect &&
78 git log -1 --format=%ad $commit >actual &&
79 test_cmp expect actual
82 # date is within 2^63-1, but enough to choke glibc's gmtime
83 test_expect_success 'absurdly far-in-future date' '
84 commit=$(munge_author_date HEAD 999999999999999999) &&
85 git log -1 --format=%ad $commit
88 test_done