3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='Pathspec restrictions
13 TEST_PASSES_SANITIZE_LEAK
=true
15 .
"$TEST_DIRECTORY"/lib-diff.sh
;# test-lib chdir's into trash
21 echo rezrov >path1/file1 &&
22 before0=$(git hash-object file0) &&
23 before1=$(git hash-object path1/file1) &&
24 git update-index --add file0 path1/file1 &&
25 tree=$(git write-tree) &&
28 echo yomin >path1/file1 &&
29 after0=$(git hash-object file0) &&
30 after1=$(git hash-object path1/file1) &&
31 git update-index file0 path1/file1'
36 'limit to path should show nothing' \
37 'git diff-index --cached $tree -- path >current &&
38 compare_diff_raw current expected'
41 :100644 100644 $before1 $after1 M path1/file1
44 'limit to path1 should show path1/file1' \
45 'git diff-index --cached $tree -- path1 >current &&
46 compare_diff_raw current expected'
49 :100644 100644 $before1 $after1 M path1/file1
52 'limit to path1/ should show path1/file1' \
53 'git diff-index --cached $tree -- path1/ >current &&
54 compare_diff_raw current expected'
57 :100644 100644 $before1 $after1 M path1/file1
60 '"*file1" should show path1/file1' \
61 'git diff-index --cached $tree -- "*file1" >current &&
62 compare_diff_raw current expected'
65 :100644 100644 $before0 $after0 M file0
68 'limit to file0 should show file0' \
69 'git diff-index --cached $tree -- file0 >current &&
70 compare_diff_raw current expected'
75 'limit to file0/ should emit nothing.' \
76 'git diff-index --cached $tree -- file0/ >current &&
77 compare_diff_raw current expected'
79 test_expect_success
'diff-tree pathspec' '
80 tree2=$(git write-tree) &&
82 git diff-tree -r --name-only $tree $tree2 -- pa path1/a >current &&
83 test_must_be_empty current
86 test_expect_success
'diff-tree with wildcard shows dir also matches' '
87 git diff-tree --name-only $EMPTY_TREE $tree -- "f*" >result &&
88 echo file0 >expected &&
89 test_cmp expected result
92 test_expect_success
'diff-tree -r with wildcard' '
93 git diff-tree -r --name-only $EMPTY_TREE $tree -- "*file1" >result &&
94 echo path1/file1 >expected &&
95 test_cmp expected result
98 test_expect_success
'diff-tree with wildcard shows dir also matches' '
99 git diff-tree --name-only $tree $tree2 -- "path1/f*" >result &&
100 echo path1 >expected &&
101 test_cmp expected result
104 test_expect_success
'diff-tree -r with wildcard from beginning' '
105 git diff-tree -r --name-only $tree $tree2 -- "path1/*file1" >result &&
106 echo path1/file1 >expected &&
107 test_cmp expected result
110 test_expect_success
'diff-tree -r with wildcard' '
111 git diff-tree -r --name-only $tree $tree2 -- "path1/f*" >result &&
112 echo path1/file1 >expected &&
113 test_cmp expected result
116 test_expect_success
'setup submodules' '
119 ( cd submod && test_commit first ) &&
121 git commit -m first &&
122 ( cd submod && test_commit second ) &&
127 test_expect_success
'diff-tree ignores trailing slash on submodule path' '
128 git diff --name-only HEAD^ HEAD submod >expect &&
129 git diff --name-only HEAD^ HEAD submod/ >actual &&
130 test_cmp expect actual &&
131 git diff --name-only HEAD^ HEAD -- submod/whatever >actual &&
132 test_must_be_empty actual
135 test_expect_success
'diff multiple wildcard pathspecs' '
137 echo rezrov >path2/file1 &&
138 git update-index --add path2/file1 &&
139 tree3=$(git write-tree) &&
140 git diff --name-only $tree $tree3 -- "path2*1" "path1*1" >actual &&
141 cat <<-\EOF >expect &&
145 test_cmp expect actual
148 test_expect_success
'diff-cache ignores trailing slash on submodule path' '
149 git diff --name-only HEAD^ submod >expect &&
150 git diff --name-only HEAD^ submod/ >actual &&
151 test_cmp expect actual