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 |
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)
14'
15
16test_expect_success 'fsck notices broken commit' '
17 test_must_fail git fsck 2>actual &&
18 test_i18ngrep invalid.author actual
19'
20
21test_expect_success 'git log with broken author email' '
22 {
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 &&
29
30 git log broken_email >actual.out 2>actual.err &&
31
32 test_cmp expect.out actual.out &&
33 test_must_be_empty actual.err
34'
35
36test_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 &&
38
39 git log --format="%an+%ae+%ad" broken_email >actual.out 2>actual.err &&
40
41 test_cmp expect.out actual.out &&
42 test_must_be_empty actual.err
43'
44
45munge_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
49}
50
51test_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
57'
58
59test_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
64'
65
66# date is 2^64 + 1
67test_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
72'
73
74# date is 2^64 - 2
75test_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
80'
81
82# date is within 2^63-1, but enough to choke glibc's gmtime
83test_expect_success 'absurdly far-in-future date' '
84 commit=$(munge_author_date HEAD 999999999999999999) &&
85 git log -1 --format=%ad $commit
86'
87
88test_done