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