]>
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 | ' | |
12 | . ./test-lib.sh | |
bfdbee98 | 13 | . "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash |
66204988 JH |
14 | |
15 | test_expect_success \ | |
16 | setup \ | |
17 | 'echo frotz >file0 && | |
18 | mkdir path1 && | |
19 | echo rezrov >path1/file1 && | |
32a67072 | 20 | before0=$(git hash-object file0) && |
21 | before1=$(git hash-object path1/file1) && | |
5be60078 | 22 | git update-index --add file0 path1/file1 && |
38b2e5d1 | 23 | tree=$(git write-tree) && |
66204988 JH |
24 | echo "$tree" && |
25 | echo nitfol >file0 && | |
26 | echo yomin >path1/file1 && | |
32a67072 | 27 | after0=$(git hash-object file0) && |
28 | after1=$(git hash-object path1/file1) && | |
5be60078 | 29 | git update-index file0 path1/file1' |
66204988 JH |
30 | |
31 | cat >expected <<\EOF | |
32 | EOF | |
33 | test_expect_success \ | |
34 | 'limit to path should show nothing' \ | |
5be60078 | 35 | 'git diff-index --cached $tree -- path >current && |
66204988 JH |
36 | compare_diff_raw current expected' |
37 | ||
32a67072 | 38 | cat >expected <<EOF |
39 | :100644 100644 $before1 $after1 M path1/file1 | |
66204988 JH |
40 | EOF |
41 | test_expect_success \ | |
42 | 'limit to path1 should show path1/file1' \ | |
5be60078 | 43 | 'git diff-index --cached $tree -- path1 >current && |
66204988 JH |
44 | compare_diff_raw current expected' |
45 | ||
32a67072 | 46 | cat >expected <<EOF |
47 | :100644 100644 $before1 $after1 M path1/file1 | |
66204988 JH |
48 | EOF |
49 | test_expect_success \ | |
50 | 'limit to path1/ should show path1/file1' \ | |
5be60078 | 51 | 'git diff-index --cached $tree -- path1/ >current && |
66204988 JH |
52 | compare_diff_raw current expected' |
53 | ||
32a67072 | 54 | cat >expected <<EOF |
55 | :100644 100644 $before1 $after1 M path1/file1 | |
4838237c NTND |
56 | EOF |
57 | test_expect_success \ | |
58 | '"*file1" should show path1/file1' \ | |
59 | 'git diff-index --cached $tree -- "*file1" >current && | |
60 | compare_diff_raw current expected' | |
61 | ||
32a67072 | 62 | cat >expected <<EOF |
63 | :100644 100644 $before0 $after0 M file0 | |
66204988 JH |
64 | EOF |
65 | test_expect_success \ | |
66 | 'limit to file0 should show file0' \ | |
5be60078 | 67 | 'git diff-index --cached $tree -- file0 >current && |
66204988 JH |
68 | compare_diff_raw current expected' |
69 | ||
70 | cat >expected <<\EOF | |
71 | EOF | |
72 | test_expect_success \ | |
73 | 'limit to file0/ should emit nothing.' \ | |
5be60078 | 74 | 'git diff-index --cached $tree -- file0/ >current && |
66204988 JH |
75 | compare_diff_raw current expected' |
76 | ||
f0946cb8 BS |
77 | test_expect_success 'diff-tree pathspec' ' |
78 | tree2=$(git write-tree) && | |
79 | echo "$tree2" && | |
80 | git diff-tree -r --name-only $tree $tree2 -- pa path1/a >current && | |
d3c6751b | 81 | test_must_be_empty current |
f0946cb8 BS |
82 | ' |
83 | ||
d38f2809 NTND |
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 | |
88 | ' | |
89 | ||
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 | |
94 | ' | |
95 | ||
f1a2ddbb NTND |
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 | |
100 | ' | |
101 | ||
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 | |
106 | ' | |
107 | ||
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 | |
112 | ' | |
113 | ||
74b4f7f2 NTND |
114 | test_expect_success 'setup submodules' ' |
115 | test_tick && | |
116 | git init submod && | |
02779185 | 117 | ( cd submod && test_commit first ) && |
74b4f7f2 NTND |
118 | git add submod && |
119 | git commit -m first && | |
02779185 | 120 | ( cd submod && test_commit second ) && |
74b4f7f2 NTND |
121 | git add submod && |
122 | git commit -m second | |
123 | ' | |
124 | ||
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 && | |
35a9f1e9 SG |
128 | test_cmp expect actual && |
129 | git diff --name-only HEAD^ HEAD -- submod/whatever >actual && | |
130 | test_must_be_empty actual | |
74b4f7f2 NTND |
131 | ' |
132 | ||
e4ddb057 AS |
133 | test_expect_success 'diff multiple wildcard pathspecs' ' |
134 | mkdir path2 && | |
135 | echo rezrov >path2/file1 && | |
136 | git update-index --add path2/file1 && | |
38b2e5d1 | 137 | tree3=$(git write-tree) && |
e4ddb057 AS |
138 | git diff --name-only $tree $tree3 -- "path2*1" "path1*1" >actual && |
139 | cat <<-\EOF >expect && | |
140 | path1/file1 | |
141 | path2/file1 | |
142 | EOF | |
143 | test_cmp expect actual | |
144 | ' | |
145 | ||
ae8d0824 NTND |
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 | |
150 | ' | |
151 | ||
66204988 | 152 | test_done |