3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='Pathspec restrictions
13 .
"$TEST_DIRECTORY"/diff-lib.sh
;# test-lib chdir's into trash
19 echo rezrov >path1/file1 &&
20 before0=$(git hash-object file0) &&
21 before1=$(git hash-object path1/file1) &&
22 git update-index --add file0 path1/file1 &&
23 tree=$(git write-tree) &&
26 echo yomin >path1/file1 &&
27 after0=$(git hash-object file0) &&
28 after1=$(git hash-object path1/file1) &&
29 git update-index file0 path1/file1'
34 'limit to path should show nothing' \
35 'git diff-index --cached $tree -- path >current &&
36 compare_diff_raw current expected'
39 :100644 100644 $before1 $after1 M path1/file1
42 'limit to path1 should show path1/file1' \
43 'git diff-index --cached $tree -- path1 >current &&
44 compare_diff_raw current expected'
47 :100644 100644 $before1 $after1 M path1/file1
50 'limit to path1/ should show path1/file1' \
51 'git diff-index --cached $tree -- path1/ >current &&
52 compare_diff_raw current expected'
55 :100644 100644 $before1 $after1 M path1/file1
58 '"*file1" should show path1/file1' \
59 'git diff-index --cached $tree -- "*file1" >current &&
60 compare_diff_raw current expected'
63 :100644 100644 $before0 $after0 M file0
66 'limit to file0 should show file0' \
67 'git diff-index --cached $tree -- file0 >current &&
68 compare_diff_raw current expected'
73 'limit to file0/ should emit nothing.' \
74 'git diff-index --cached $tree -- file0/ >current &&
75 compare_diff_raw current expected'
77 test_expect_success
'diff-tree pathspec' '
78 tree2=$(git write-tree) &&
80 git diff-tree -r --name-only $tree $tree2 -- pa path1/a >current &&
81 test_must_be_empty current
84 test_expect_success
'diff-tree with wildcard shows dir also matches' '
85 git diff-tree --name-only $EMPTY_TREE $tree -- "f*" >result &&
86 echo file0 >expected &&
87 test_cmp expected result
90 test_expect_success
'diff-tree -r with wildcard' '
91 git diff-tree -r --name-only $EMPTY_TREE $tree -- "*file1" >result &&
92 echo path1/file1 >expected &&
93 test_cmp expected result
96 test_expect_success
'diff-tree with wildcard shows dir also matches' '
97 git diff-tree --name-only $tree $tree2 -- "path1/f*" >result &&
98 echo path1 >expected &&
99 test_cmp expected result
102 test_expect_success
'diff-tree -r with wildcard from beginning' '
103 git diff-tree -r --name-only $tree $tree2 -- "path1/*file1" >result &&
104 echo path1/file1 >expected &&
105 test_cmp expected result
108 test_expect_success
'diff-tree -r with wildcard' '
109 git diff-tree -r --name-only $tree $tree2 -- "path1/f*" >result &&
110 echo path1/file1 >expected &&
111 test_cmp expected result
114 test_expect_success
'setup submodules' '
117 ( cd submod && test_commit first ) &&
119 git commit -m first &&
120 ( cd submod && test_commit second ) &&
125 test_expect_success
'diff-tree ignores trailing slash on submodule path' '
126 git diff --name-only HEAD^ HEAD submod >expect &&
127 git diff --name-only HEAD^ HEAD submod/ >actual &&
128 test_cmp expect actual &&
129 git diff --name-only HEAD^ HEAD -- submod/whatever >actual &&
130 test_must_be_empty actual
133 test_expect_success
'diff multiple wildcard pathspecs' '
135 echo rezrov >path2/file1 &&
136 git update-index --add path2/file1 &&
137 tree3=$(git write-tree) &&
138 git diff --name-only $tree $tree3 -- "path2*1" "path1*1" >actual &&
139 cat <<-\EOF >expect &&
143 test_cmp expect actual
146 test_expect_success
'diff-cache ignores trailing slash on submodule path' '
147 git diff --name-only HEAD^ submod >expect &&
148 git diff --name-only HEAD^ submod/ >actual &&
149 test_cmp expect actual