#!/bin/sh global test_description := ''git log with invalid commit headers'' source ./test-lib.sh test_expect_success 'setup' ' test_commit foo && git cat-file commit HEAD | sed "/^author /s/>/>-<>/" >broken_email.commit && git hash-object -w -t commit broken_email.commit >broken_email.hash && git update-ref refs/heads/broken_email $(cat broken_email.hash) ' test_expect_success 'fsck notices broken commit' ' test_must_fail git fsck 2>actual && test_i18ngrep invalid.author actual ' test_expect_success 'git log with broken author email' ' { echo commit $(cat broken_email.hash) echo "Author: A U Thor " echo "Date: Thu Apr 7 15:13:13 2005 -0700" echo echo " foo" } >expect.out && : >expect.err && git log broken_email >actual.out 2>actual.err && test_cmp expect.out actual.out && test_cmp expect.err actual.err ' test_expect_success 'git log --format with broken author email' ' echo "A U Thor+author@example.com+Thu Apr 7 15:13:13 2005 -0700" >expect.out && : >expect.err && git log --format="%an+%ae+%ad" broken_email >actual.out 2>actual.err && test_cmp expect.out actual.out && test_cmp expect.err actual.err ' proc munge_author_date { git cat-file commit $1 >commit.orig && sed "s/^\(author .*>\) [0-9]*/\1 $2/" commit.munge && git hash-object -w -t commit commit.munge } test_expect_success 'unparsable dates produce sentinel value' ' commit=$(munge_author_date HEAD totally_bogus) && echo "Date: Thu Jan 1 00:00:00 1970 +0000" >expect && git log -1 $commit >actual.full && grep Date actual && test_cmp expect actual ' test_expect_success 'unparsable dates produce sentinel value (%ad)' ' commit=$(munge_author_date HEAD totally_bogus) && echo >expect && git log -1 --format=%ad $commit >actual && test_cmp expect actual ' # date is 2^64 + 1 test_expect_success 'date parser recognizes integer overflow' ' commit=$(munge_author_date HEAD 18446744073709551617) && echo "Thu Jan 1 00:00:00 1970 +0000" >expect && git log -1 --format=%ad $commit >actual && test_cmp expect actual ' # date is 2^64 - 2 test_expect_success 'date parser recognizes time_t overflow' ' commit=$(munge_author_date HEAD 18446744073709551614) && echo "Thu Jan 1 00:00:00 1970 +0000" >expect && git log -1 --format=%ad $commit >actual && test_cmp expect actual ' # date is within 2^63-1, but enough to choke glibc's gmtime test_expect_success 'absurdly far-in-future date' ' commit=$(munge_author_date HEAD 999999999999999999) && git log -1 --format=%ad $commit ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"git log with invalid commit headers">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\ttest_commit foo &&\n"> <"\n"> <"\tgit cat-file commit HEAD |\n"> <"\tsed \"/^author /s/>/>-<>/\" >broken_email.commit &&\n"> <"\tgit hash-object -w -t commit broken_email.commit >broken_email.hash &&\n"> <"\tgit update-ref refs/heads/broken_email $(cat broken_email.hash)\n"> ) } ) (C {(test_expect_success)} {(SQ <"fsck notices broken commit">)} { (SQ <"\n"> <"\ttest_must_fail git fsck 2>actual &&\n"> <"\ttest_i18ngrep invalid.author actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"git log with broken author email">)} { (SQ <"\n"> <"\t{\n"> <"\t\techo commit $(cat broken_email.hash)\n"> <"\t\techo \"Author: A U Thor \"\n"> <"\t\techo \"Date: Thu Apr 7 15:13:13 2005 -0700\"\n"> <"\t\techo\n"> <"\t\techo \" foo\"\n"> <"\t} >expect.out &&\n"> <"\t: >expect.err &&\n"> <"\n"> <"\tgit log broken_email >actual.out 2>actual.err &&\n"> <"\n"> <"\ttest_cmp expect.out actual.out &&\n"> <"\ttest_cmp expect.err actual.err\n"> ) } ) (C {(test_expect_success)} {(SQ <"git log --format with broken author email">)} { (SQ <"\n"> <"\techo \"A U Thor+author@example.com+Thu Apr 7 15:13:13 2005 -0700\" >expect.out &&\n"> <"\t: >expect.err &&\n"> <"\n"> <"\tgit log --format=\"%an+%ae+%ad\" broken_email >actual.out 2>actual.err &&\n"> <"\n"> <"\ttest_cmp expect.out actual.out &&\n"> <"\ttest_cmp expect.err actual.err\n"> ) } ) (FuncDef name: munge_author_date body: (BraceGroup children: [ (AndOr children: [ (SimpleCommand words: [{(git)} {(cat-file)} {(commit)} {(DQ ($ VSub_Number "$1"))}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(commit.orig)} spids:[105])] ) (AndOr children: [ (SimpleCommand words: [ {(sed)} { (DQ ("s/^") (EscapedLiteralPart token:) ("author .*>") (EscapedLiteralPart token: ) (" [0-9]*/") (EscapedLiteralPart token:) (" ") ($ VSub_Number "$2") (/) ) } ] redirects: [ (Redir op_id: Redir_Less fd: -1 arg_word: {(commit.orig)} spids: [125] ) (Redir op_id: Redir_Great fd: -1 arg_word: {(commit.munge)} spids: [128] ) ] ) (C {(git)} {(hash-object)} {(-w)} {(-t)} {(commit)} {(commit.munge)}) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [92] ) spids: [87 91] ) (C {(test_expect_success)} {(SQ <"unparsable dates produce sentinel value">)} { (SQ <"\n"> <"\tcommit=$(munge_author_date HEAD totally_bogus) &&\n"> <"\techo \"Date: Thu Jan 1 00:00:00 1970 +0000\" >expect &&\n"> <"\tgit log -1 $commit >actual.full &&\n"> <"\tgrep Date actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"unparsable dates produce sentinel value (%ad)">)} { (SQ <"\n"> <"\tcommit=$(munge_author_date HEAD totally_bogus) &&\n"> <"\techo >expect &&\n"> <"\tgit log -1 --format=%ad $commit >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"date parser recognizes integer overflow">)} { (SQ <"\n"> <"\tcommit=$(munge_author_date HEAD 18446744073709551617) &&\n"> <"\techo \"Thu Jan 1 00:00:00 1970 +0000\" >expect &&\n"> <"\tgit log -1 --format=%ad $commit >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"date parser recognizes time_t overflow">)} { (SQ <"\n"> <"\tcommit=$(munge_author_date HEAD 18446744073709551614) &&\n"> <"\techo \"Thu Jan 1 00:00:00 1970 +0000\" >expect &&\n"> <"\tgit log -1 --format=%ad $commit >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"absurdly far-in-future date">)} { (SQ <"\n"> <"\tcommit=$(munge_author_date HEAD 999999999999999999) &&\n"> <"\tgit log -1 --format=%ad $commit\n"> ) } ) (C {(test_done)}) ] )