]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4054-diff-bogus-tree.sh
Merge branch 'en/fetch-negotiation-default-fix'
[thirdparty/git.git] / t / t4054-diff-bogus-tree.sh
CommitLineData
e5450100
JK
1#!/bin/sh
2
3test_description='test diff with a bogus tree containing the null sha1'
16d4bd4f
ÆAB
4
5TEST_PASSES_SANITIZE_LEAK=true
e5450100
JK
6. ./test-lib.sh
7
e5450100 8test_expect_success 'create bogus tree' '
194264c1 9 name=$(echo $ZERO_OID | sed -e "s/00/Q/g") &&
e5450100 10 bogus_tree=$(
194264c1 11 printf "100644 fooQ$name" |
e5450100
JK
12 q_to_nul |
13 git hash-object -w --stdin -t tree
14 )
15'
16
17test_expect_success 'create tree with matching file' '
18 echo bar >foo &&
19 git add foo &&
99094a7a 20 good_tree=$(git write-tree) &&
e5450100
JK
21 blob=$(git rev-parse :foo)
22'
23
24test_expect_success 'raw diff shows null sha1 (addition)' '
8125a58b 25 echo ":000000 100644 $ZERO_OID $ZERO_OID A foo" >expect &&
f9e7d9f8 26 git diff-tree $EMPTY_TREE $bogus_tree >actual &&
e5450100
JK
27 test_cmp expect actual
28'
29
30test_expect_success 'raw diff shows null sha1 (removal)' '
8125a58b 31 echo ":100644 000000 $ZERO_OID $ZERO_OID D foo" >expect &&
f9e7d9f8 32 git diff-tree $bogus_tree $EMPTY_TREE >actual &&
e5450100
JK
33 test_cmp expect actual
34'
35
36test_expect_success 'raw diff shows null sha1 (modification)' '
8125a58b 37 echo ":100644 100644 $blob $ZERO_OID M foo" >expect &&
e5450100
JK
38 git diff-tree $good_tree $bogus_tree >actual &&
39 test_cmp expect actual
40'
41
42test_expect_success 'raw diff shows null sha1 (other direction)' '
8125a58b 43 echo ":100644 100644 $ZERO_OID $blob M foo" >expect &&
e5450100
JK
44 git diff-tree $bogus_tree $good_tree >actual &&
45 test_cmp expect actual
46'
47
48test_expect_success 'raw diff shows null sha1 (reverse)' '
8125a58b 49 echo ":100644 100644 $ZERO_OID $blob M foo" >expect &&
e5450100
JK
50 git diff-tree -R $good_tree $bogus_tree >actual &&
51 test_cmp expect actual
52'
53
54test_expect_success 'raw diff shows null sha1 (index)' '
8125a58b 55 echo ":100644 100644 $ZERO_OID $blob M foo" >expect &&
e5450100
JK
56 git diff-index $bogus_tree >actual &&
57 test_cmp expect actual
58'
59
60test_expect_success 'patch fails due to bogus sha1 (addition)' '
f9e7d9f8 61 test_must_fail git diff-tree -p $EMPTY_TREE $bogus_tree
e5450100
JK
62'
63
64test_expect_success 'patch fails due to bogus sha1 (removal)' '
f9e7d9f8 65 test_must_fail git diff-tree -p $bogus_tree $EMPTY_TREE
e5450100
JK
66'
67
68test_expect_success 'patch fails due to bogus sha1 (modification)' '
69 test_must_fail git diff-tree -p $good_tree $bogus_tree
70'
71
72test_expect_success 'patch fails due to bogus sha1 (other direction)' '
73 test_must_fail git diff-tree -p $bogus_tree $good_tree
74'
75
76test_expect_success 'patch fails due to bogus sha1 (reverse)' '
77 test_must_fail git diff-tree -R -p $good_tree $bogus_tree
78'
79
80test_expect_success 'patch fails due to bogus sha1 (index)' '
81 test_must_fail git diff-index -p $bogus_tree
82'
83
84test_done