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