#!/bin/sh global test_description := ''test diff with a bogus tree containing the null sha1'' source ./test-lib.sh test_expect_success 'create bogus tree' ' bogus_tree=$( printf "100644 fooQQQQQQQQQQQQQQQQQQQQQ" | q_to_nul | git hash-object -w --stdin -t tree ) ' test_expect_success 'create tree with matching file' ' echo bar >foo && git add foo && good_tree=$(git write-tree) && blob=$(git rev-parse :foo) ' test_expect_success 'raw diff shows null sha1 (addition)' ' echo ":000000 100644 $_z40 $_z40 A foo" >expect && git diff-tree $EMPTY_TREE $bogus_tree >actual && test_cmp expect actual ' test_expect_success 'raw diff shows null sha1 (removal)' ' echo ":100644 000000 $_z40 $_z40 D foo" >expect && git diff-tree $bogus_tree $EMPTY_TREE >actual && test_cmp expect actual ' test_expect_success 'raw diff shows null sha1 (modification)' ' echo ":100644 100644 $blob $_z40 M foo" >expect && git diff-tree $good_tree $bogus_tree >actual && test_cmp expect actual ' test_expect_success 'raw diff shows null sha1 (other direction)' ' echo ":100644 100644 $_z40 $blob M foo" >expect && git diff-tree $bogus_tree $good_tree >actual && test_cmp expect actual ' test_expect_success 'raw diff shows null sha1 (reverse)' ' echo ":100644 100644 $_z40 $blob M foo" >expect && git diff-tree -R $good_tree $bogus_tree >actual && test_cmp expect actual ' test_expect_success 'raw diff shows null sha1 (index)' ' echo ":100644 100644 $_z40 $blob M foo" >expect && git diff-index $bogus_tree >actual && test_cmp expect actual ' test_expect_success 'patch fails due to bogus sha1 (addition)' ' test_must_fail git diff-tree -p $EMPTY_TREE $bogus_tree ' test_expect_success 'patch fails due to bogus sha1 (removal)' ' test_must_fail git diff-tree -p $bogus_tree $EMPTY_TREE ' test_expect_success 'patch fails due to bogus sha1 (modification)' ' test_must_fail git diff-tree -p $good_tree $bogus_tree ' test_expect_success 'patch fails due to bogus sha1 (other direction)' ' test_must_fail git diff-tree -p $bogus_tree $good_tree ' test_expect_success 'patch fails due to bogus sha1 (reverse)' ' test_must_fail git diff-tree -R -p $good_tree $bogus_tree ' test_expect_success 'patch fails due to bogus sha1 (index)' ' test_must_fail git diff-index -p $bogus_tree ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"test diff with a bogus tree containing the null sha1">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ <"create bogus tree">)} { (SQ <"\n"> <"\tbogus_tree=$(\n"> <"\t\tprintf \"100644 fooQQQQQQQQQQQQQQQQQQQQQ\" |\n"> <"\t\tq_to_nul |\n"> <"\t\tgit hash-object -w --stdin -t tree\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"create tree with matching file">)} { (SQ <"\n"> <"\techo bar >foo &&\n"> <"\tgit add foo &&\n"> <"\tgood_tree=$(git write-tree) &&\n"> <"\tblob=$(git rev-parse :foo)\n"> ) } ) (C {(test_expect_success)} {(SQ <"raw diff shows null sha1 (addition)">)} { (SQ <"\n"> <"\techo \":000000 100644 $_z40 $_z40 A\tfoo\" >expect &&\n"> <"\tgit diff-tree $EMPTY_TREE $bogus_tree >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"raw diff shows null sha1 (removal)">)} { (SQ <"\n"> <"\techo \":100644 000000 $_z40 $_z40 D\tfoo\" >expect &&\n"> <"\tgit diff-tree $bogus_tree $EMPTY_TREE >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"raw diff shows null sha1 (modification)">)} { (SQ <"\n"> <"\techo \":100644 100644 $blob $_z40 M\tfoo\" >expect &&\n"> <"\tgit diff-tree $good_tree $bogus_tree >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"raw diff shows null sha1 (other direction)">)} { (SQ <"\n"> <"\techo \":100644 100644 $_z40 $blob M\tfoo\" >expect &&\n"> <"\tgit diff-tree $bogus_tree $good_tree >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"raw diff shows null sha1 (reverse)">)} { (SQ <"\n"> <"\techo \":100644 100644 $_z40 $blob M\tfoo\" >expect &&\n"> <"\tgit diff-tree -R $good_tree $bogus_tree >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"raw diff shows null sha1 (index)">)} { (SQ <"\n"> <"\techo \":100644 100644 $_z40 $blob M\tfoo\" >expect &&\n"> <"\tgit diff-index $bogus_tree >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"patch fails due to bogus sha1 (addition)">)} {(SQ <"\n"> <"\ttest_must_fail git diff-tree -p $EMPTY_TREE $bogus_tree\n">)} ) (C {(test_expect_success)} {(SQ <"patch fails due to bogus sha1 (removal)">)} {(SQ <"\n"> <"\ttest_must_fail git diff-tree -p $bogus_tree $EMPTY_TREE\n">)} ) (C {(test_expect_success)} {(SQ <"patch fails due to bogus sha1 (modification)">)} {(SQ <"\n"> <"\ttest_must_fail git diff-tree -p $good_tree $bogus_tree\n">)} ) (C {(test_expect_success)} {(SQ <"patch fails due to bogus sha1 (other direction)">)} {(SQ <"\n"> <"\ttest_must_fail git diff-tree -p $bogus_tree $good_tree\n">)} ) (C {(test_expect_success)} {(SQ <"patch fails due to bogus sha1 (reverse)">)} {(SQ <"\n"> <"\ttest_must_fail git diff-tree -R -p $good_tree $bogus_tree\n">)} ) (C {(test_expect_success)} {(SQ <"patch fails due to bogus sha1 (index)">)} {(SQ <"\n"> <"\ttest_must_fail git diff-index -p $bogus_tree\n">)} ) (C {(test_done)}) ] )