Merge branch 'pt/xdg-config-path' into next
[git/mjg.git] / t / t4058-diff-duplicates.sh
blob0a23242cb6aab7903aac9b767b0c4913208c044b
1 #!/bin/sh
3 test_description='test tree diff when trees have duplicate entries'
4 . ./test-lib.sh
6 # make_tree_entry <mode> <mode> <sha1>
8 # We have to rely on perl here because not all printfs understand
9 # hex escapes (only octal), and xxd is not portable.
10 make_tree_entry () {
11 printf '%s %s\0' "$1" "$2" &&
12 perl -e 'print chr(hex($_)) for ($ARGV[0] =~ /../g)' "$3"
15 # Like git-mktree, but without all of the pesky sanity checking.
16 # Arguments come in groups of three, each group specifying a single
17 # tree entry (see make_tree_entry above).
18 make_tree () {
19 while test $# -gt 2; do
20 make_tree_entry "$1" "$2" "$3"
21 shift; shift; shift
22 done |
23 git hash-object -w -t tree --stdin
26 # this is kind of a convoluted setup, but matches
27 # a real-world case. Each tree contains four entries
28 # for the given path, one with one sha1, and three with
29 # the other. The first tree has them split across
30 # two subtrees (which are themselves duplicate entries in
31 # the root tree), and the second has them all in a single subtree.
32 test_expect_success 'create trees with duplicate entries' '
33 blob_one=$(echo one | git hash-object -w --stdin) &&
34 blob_two=$(echo two | git hash-object -w --stdin) &&
35 inner_one_a=$(make_tree \
36 100644 inner $blob_one
37 ) &&
38 inner_one_b=$(make_tree \
39 100644 inner $blob_two \
40 100644 inner $blob_two \
41 100644 inner $blob_two
42 ) &&
43 outer_one=$(make_tree \
44 040000 outer $inner_one_a \
45 040000 outer $inner_one_b
46 ) &&
47 inner_two=$(make_tree \
48 100644 inner $blob_one \
49 100644 inner $blob_two \
50 100644 inner $blob_two \
51 100644 inner $blob_two
52 ) &&
53 outer_two=$(make_tree \
54 040000 outer $inner_two
55 ) &&
56 git tag one $outer_one &&
57 git tag two $outer_two
60 test_expect_success 'diff-tree between trees' '
62 printf ":000000 100644 $_z40 $blob_two A\touter/inner\n" &&
63 printf ":000000 100644 $_z40 $blob_two A\touter/inner\n" &&
64 printf ":000000 100644 $_z40 $blob_two A\touter/inner\n" &&
65 printf ":100644 000000 $blob_two $_z40 D\touter/inner\n" &&
66 printf ":100644 000000 $blob_two $_z40 D\touter/inner\n" &&
67 printf ":100644 000000 $blob_two $_z40 D\touter/inner\n"
68 } >expect &&
69 git diff-tree -r --no-abbrev one two >actual &&
70 test_cmp expect actual
73 test_expect_success 'diff-tree with renames' '
74 # same expectation as above, since we disable rename detection
75 git diff-tree -M -r --no-abbrev one two >actual &&
76 test_cmp expect actual
79 test_done