]>
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 && | |
5be60078 | 20 | git update-index --add file0 path1/file1 && |
38b2e5d1 | 21 | tree=$(git write-tree) && |
66204988 JH |
22 | echo "$tree" && |
23 | echo nitfol >file0 && | |
24 | echo yomin >path1/file1 && | |
5be60078 | 25 | git update-index file0 path1/file1' |
66204988 JH |
26 | |
27 | cat >expected <<\EOF | |
28 | EOF | |
29 | test_expect_success \ | |
30 | 'limit to path should show nothing' \ | |
5be60078 | 31 | 'git diff-index --cached $tree -- path >current && |
66204988 JH |
32 | compare_diff_raw current expected' |
33 | ||
34 | cat >expected <<\EOF | |
35 | :100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M path1/file1 | |
36 | EOF | |
37 | test_expect_success \ | |
38 | 'limit to path1 should show path1/file1' \ | |
5be60078 | 39 | 'git diff-index --cached $tree -- path1 >current && |
66204988 JH |
40 | compare_diff_raw current expected' |
41 | ||
42 | cat >expected <<\EOF | |
43 | :100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M path1/file1 | |
44 | EOF | |
45 | test_expect_success \ | |
46 | 'limit to path1/ should show path1/file1' \ | |
5be60078 | 47 | 'git diff-index --cached $tree -- path1/ >current && |
66204988 JH |
48 | compare_diff_raw current expected' |
49 | ||
4838237c NTND |
50 | cat >expected <<\EOF |
51 | :100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M path1/file1 | |
52 | EOF | |
53 | test_expect_success \ | |
54 | '"*file1" should show path1/file1' \ | |
55 | 'git diff-index --cached $tree -- "*file1" >current && | |
56 | compare_diff_raw current expected' | |
57 | ||
66204988 | 58 | cat >expected <<\EOF |
bb8db1b5 | 59 | :100644 100644 8e4020bb5a8d8c873b25de15933e75cc0fc275df dca6b92303befc93086aa025d90a5facd7eb2812 M file0 |
66204988 JH |
60 | EOF |
61 | test_expect_success \ | |
62 | 'limit to file0 should show file0' \ | |
5be60078 | 63 | 'git diff-index --cached $tree -- file0 >current && |
66204988 JH |
64 | compare_diff_raw current expected' |
65 | ||
66 | cat >expected <<\EOF | |
67 | EOF | |
68 | test_expect_success \ | |
69 | 'limit to file0/ should emit nothing.' \ | |
5be60078 | 70 | 'git diff-index --cached $tree -- file0/ >current && |
66204988 JH |
71 | compare_diff_raw current expected' |
72 | ||
f0946cb8 BS |
73 | test_expect_success 'diff-tree pathspec' ' |
74 | tree2=$(git write-tree) && | |
75 | echo "$tree2" && | |
76 | git diff-tree -r --name-only $tree $tree2 -- pa path1/a >current && | |
d3c6751b | 77 | test_must_be_empty current |
f0946cb8 BS |
78 | ' |
79 | ||
d38f2809 NTND |
80 | test_expect_success 'diff-tree with wildcard shows dir also matches' ' |
81 | git diff-tree --name-only $EMPTY_TREE $tree -- "f*" >result && | |
82 | echo file0 >expected && | |
83 | test_cmp expected result | |
84 | ' | |
85 | ||
86 | test_expect_success 'diff-tree -r with wildcard' ' | |
87 | git diff-tree -r --name-only $EMPTY_TREE $tree -- "*file1" >result && | |
88 | echo path1/file1 >expected && | |
89 | test_cmp expected result | |
90 | ' | |
91 | ||
f1a2ddbb NTND |
92 | test_expect_success 'diff-tree with wildcard shows dir also matches' ' |
93 | git diff-tree --name-only $tree $tree2 -- "path1/f*" >result && | |
94 | echo path1 >expected && | |
95 | test_cmp expected result | |
96 | ' | |
97 | ||
98 | test_expect_success 'diff-tree -r with wildcard from beginning' ' | |
99 | git diff-tree -r --name-only $tree $tree2 -- "path1/*file1" >result && | |
100 | echo path1/file1 >expected && | |
101 | test_cmp expected result | |
102 | ' | |
103 | ||
104 | test_expect_success 'diff-tree -r with wildcard' ' | |
105 | git diff-tree -r --name-only $tree $tree2 -- "path1/f*" >result && | |
106 | echo path1/file1 >expected && | |
107 | test_cmp expected result | |
108 | ' | |
109 | ||
74b4f7f2 NTND |
110 | test_expect_success 'setup submodules' ' |
111 | test_tick && | |
112 | git init submod && | |
02779185 | 113 | ( cd submod && test_commit first ) && |
74b4f7f2 NTND |
114 | git add submod && |
115 | git commit -m first && | |
02779185 | 116 | ( cd submod && test_commit second ) && |
74b4f7f2 NTND |
117 | git add submod && |
118 | git commit -m second | |
119 | ' | |
120 | ||
121 | test_expect_success 'diff-tree ignores trailing slash on submodule path' ' | |
122 | git diff --name-only HEAD^ HEAD submod >expect && | |
123 | git diff --name-only HEAD^ HEAD submod/ >actual && | |
124 | test_cmp expect actual | |
125 | ' | |
126 | ||
e4ddb057 AS |
127 | test_expect_success 'diff multiple wildcard pathspecs' ' |
128 | mkdir path2 && | |
129 | echo rezrov >path2/file1 && | |
130 | git update-index --add path2/file1 && | |
38b2e5d1 | 131 | tree3=$(git write-tree) && |
e4ddb057 AS |
132 | git diff --name-only $tree $tree3 -- "path2*1" "path1*1" >actual && |
133 | cat <<-\EOF >expect && | |
134 | path1/file1 | |
135 | path2/file1 | |
136 | EOF | |
137 | test_cmp expect actual | |
138 | ' | |
139 | ||
ae8d0824 NTND |
140 | test_expect_success 'diff-cache ignores trailing slash on submodule path' ' |
141 | git diff --name-only HEAD^ submod >expect && | |
142 | git diff --name-only HEAD^ submod/ >actual && | |
143 | test_cmp expect actual | |
144 | ' | |
145 | ||
66204988 | 146 | test_done |