]>
Commit | Line | Data |
---|---|---|
66204988 JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano | |
4 | # | |
5 | ||
6 | test_description='Pathspec restrictions | |
7 | ||
8 | Prepare: | |
9 | file0 | |
10 | path1/file1 | |
11 | ' | |
16d4bd4f | 12 | |
66204988 | 13 | . ./test-lib.sh |
ebd73f50 | 14 | . "$TEST_DIRECTORY"/lib-diff.sh ;# test-lib chdir's into trash |
66204988 JH |
15 | |
16 | test_expect_success \ | |
17 | setup \ | |
18 | 'echo frotz >file0 && | |
19 | mkdir path1 && | |
20 | echo rezrov >path1/file1 && | |
32a67072 | 21 | before0=$(git hash-object file0) && |
22 | before1=$(git hash-object path1/file1) && | |
5be60078 | 23 | git update-index --add file0 path1/file1 && |
38b2e5d1 | 24 | tree=$(git write-tree) && |
66204988 JH |
25 | echo "$tree" && |
26 | echo nitfol >file0 && | |
27 | echo yomin >path1/file1 && | |
32a67072 | 28 | after0=$(git hash-object file0) && |
29 | after1=$(git hash-object path1/file1) && | |
5be60078 | 30 | git update-index file0 path1/file1' |
66204988 JH |
31 | |
32 | cat >expected <<\EOF | |
33 | EOF | |
34 | test_expect_success \ | |
35 | 'limit to path should show nothing' \ | |
5be60078 | 36 | 'git diff-index --cached $tree -- path >current && |
66204988 JH |
37 | compare_diff_raw current expected' |
38 | ||
32a67072 | 39 | cat >expected <<EOF |
40 | :100644 100644 $before1 $after1 M path1/file1 | |
66204988 JH |
41 | EOF |
42 | test_expect_success \ | |
43 | 'limit to path1 should show path1/file1' \ | |
5be60078 | 44 | 'git diff-index --cached $tree -- path1 >current && |
66204988 JH |
45 | compare_diff_raw current expected' |
46 | ||
32a67072 | 47 | cat >expected <<EOF |
48 | :100644 100644 $before1 $after1 M path1/file1 | |
66204988 JH |
49 | EOF |
50 | test_expect_success \ | |
51 | 'limit to path1/ should show path1/file1' \ | |
5be60078 | 52 | 'git diff-index --cached $tree -- path1/ >current && |
66204988 JH |
53 | compare_diff_raw current expected' |
54 | ||
32a67072 | 55 | cat >expected <<EOF |
56 | :100644 100644 $before1 $after1 M path1/file1 | |
4838237c NTND |
57 | EOF |
58 | test_expect_success \ | |
59 | '"*file1" should show path1/file1' \ | |
60 | 'git diff-index --cached $tree -- "*file1" >current && | |
61 | compare_diff_raw current expected' | |
62 | ||
32a67072 | 63 | cat >expected <<EOF |
64 | :100644 100644 $before0 $after0 M file0 | |
66204988 JH |
65 | EOF |
66 | test_expect_success \ | |
67 | 'limit to file0 should show file0' \ | |
5be60078 | 68 | 'git diff-index --cached $tree -- file0 >current && |
66204988 JH |
69 | compare_diff_raw current expected' |
70 | ||
71 | cat >expected <<\EOF | |
72 | EOF | |
73 | test_expect_success \ | |
74 | 'limit to file0/ should emit nothing.' \ | |
5be60078 | 75 | 'git diff-index --cached $tree -- file0/ >current && |
66204988 JH |
76 | compare_diff_raw current expected' |
77 | ||
f0946cb8 BS |
78 | test_expect_success 'diff-tree pathspec' ' |
79 | tree2=$(git write-tree) && | |
80 | echo "$tree2" && | |
81 | git diff-tree -r --name-only $tree $tree2 -- pa path1/a >current && | |
d3c6751b | 82 | test_must_be_empty current |
f0946cb8 BS |
83 | ' |
84 | ||
d38f2809 NTND |
85 | test_expect_success 'diff-tree with wildcard shows dir also matches' ' |
86 | git diff-tree --name-only $EMPTY_TREE $tree -- "f*" >result && | |
87 | echo file0 >expected && | |
88 | test_cmp expected result | |
89 | ' | |
90 | ||
91 | test_expect_success 'diff-tree -r with wildcard' ' | |
92 | git diff-tree -r --name-only $EMPTY_TREE $tree -- "*file1" >result && | |
93 | echo path1/file1 >expected && | |
94 | test_cmp expected result | |
95 | ' | |
96 | ||
f1a2ddbb NTND |
97 | test_expect_success 'diff-tree with wildcard shows dir also matches' ' |
98 | git diff-tree --name-only $tree $tree2 -- "path1/f*" >result && | |
99 | echo path1 >expected && | |
100 | test_cmp expected result | |
101 | ' | |
102 | ||
103 | test_expect_success 'diff-tree -r with wildcard from beginning' ' | |
104 | git diff-tree -r --name-only $tree $tree2 -- "path1/*file1" >result && | |
105 | echo path1/file1 >expected && | |
106 | test_cmp expected result | |
107 | ' | |
108 | ||
109 | test_expect_success 'diff-tree -r with wildcard' ' | |
110 | git diff-tree -r --name-only $tree $tree2 -- "path1/f*" >result && | |
111 | echo path1/file1 >expected && | |
112 | test_cmp expected result | |
113 | ' | |
114 | ||
74b4f7f2 NTND |
115 | test_expect_success 'setup submodules' ' |
116 | test_tick && | |
117 | git init submod && | |
02779185 | 118 | ( cd submod && test_commit first ) && |
74b4f7f2 NTND |
119 | git add submod && |
120 | git commit -m first && | |
02779185 | 121 | ( cd submod && test_commit second ) && |
74b4f7f2 NTND |
122 | git add submod && |
123 | git commit -m second | |
124 | ' | |
125 | ||
126 | test_expect_success 'diff-tree ignores trailing slash on submodule path' ' | |
127 | git diff --name-only HEAD^ HEAD submod >expect && | |
128 | git diff --name-only HEAD^ HEAD submod/ >actual && | |
35a9f1e9 SG |
129 | test_cmp expect actual && |
130 | git diff --name-only HEAD^ HEAD -- submod/whatever >actual && | |
131 | test_must_be_empty actual | |
74b4f7f2 NTND |
132 | ' |
133 | ||
e4ddb057 AS |
134 | test_expect_success 'diff multiple wildcard pathspecs' ' |
135 | mkdir path2 && | |
136 | echo rezrov >path2/file1 && | |
137 | git update-index --add path2/file1 && | |
38b2e5d1 | 138 | tree3=$(git write-tree) && |
e4ddb057 AS |
139 | git diff --name-only $tree $tree3 -- "path2*1" "path1*1" >actual && |
140 | cat <<-\EOF >expect && | |
141 | path1/file1 | |
142 | path2/file1 | |
143 | EOF | |
144 | test_cmp expect actual | |
145 | ' | |
146 | ||
ae8d0824 NTND |
147 | test_expect_success 'diff-cache ignores trailing slash on submodule path' ' |
148 | git diff --name-only HEAD^ submod >expect && | |
149 | git diff --name-only HEAD^ submod/ >actual && | |
150 | test_cmp expect actual | |
151 | ' | |
152 | ||
66204988 | 153 | test_done |