]>
Commit | Line | Data |
---|---|---|
2b459b48 JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='difference in submodules' | |
4 | ||
5 | . ./test-lib.sh | |
bfdbee98 | 6 | . "$TEST_DIRECTORY"/diff-lib.sh |
2b459b48 | 7 | |
2b459b48 JH |
8 | test_expect_success setup ' |
9 | test_tick && | |
10 | test_create_repo sub && | |
11 | ( | |
12 | cd sub && | |
13 | echo hello >world && | |
14 | git add world && | |
15 | git commit -m submodule | |
16 | ) && | |
17 | ||
18 | test_tick && | |
19 | echo frotz >nitfol && | |
20 | git add nitfol sub && | |
21 | git commit -m superproject && | |
22 | ||
23 | ( | |
24 | cd sub && | |
25 | echo goodbye >world && | |
26 | git add world && | |
27 | git commit -m "submodule #2" | |
28 | ) && | |
29 | ||
30 | set x $( | |
31 | cd sub && | |
32 | git rev-list HEAD | |
33 | ) && | |
8125a58b | 34 | echo ":160000 160000 $3 $ZERO_OID M sub" >expect && |
8e08b419 | 35 | subtip=$3 subprev=$2 |
2b459b48 JH |
36 | ' |
37 | ||
38 | test_expect_success 'git diff --raw HEAD' ' | |
45e2ef2b | 39 | hexsz=$(test_oid hexsz) && |
40 | git diff --raw --abbrev=$hexsz HEAD >actual && | |
82ebb0b6 | 41 | test_cmp expect actual |
2b459b48 JH |
42 | ' |
43 | ||
44 | test_expect_success 'git diff-index --raw HEAD' ' | |
45 | git diff-index --raw HEAD >actual.index && | |
82ebb0b6 | 46 | test_cmp expect actual.index |
2b459b48 JH |
47 | ' |
48 | ||
49 | test_expect_success 'git diff-files --raw' ' | |
50 | git diff-files --raw >actual.files && | |
82ebb0b6 | 51 | test_cmp expect actual.files |
2b459b48 JH |
52 | ' |
53 | ||
8e08b419 JH |
54 | expect_from_to () { |
55 | printf "%sSubproject commit %s\n+Subproject commit %s\n" \ | |
56 | "-" "$1" "$2" | |
57 | } | |
58 | ||
59 | test_expect_success 'git diff HEAD' ' | |
60 | git diff HEAD >actual && | |
61 | sed -e "1,/^@@/d" actual >actual.body && | |
62 | expect_from_to >expect.body $subtip $subprev && | |
63 | test_cmp expect.body actual.body | |
64 | ' | |
65 | ||
66 | test_expect_success 'git diff HEAD with dirty submodule (work tree)' ' | |
67 | echo >>sub/world && | |
68 | git diff HEAD >actual && | |
69 | sed -e "1,/^@@/d" actual >actual.body && | |
70 | expect_from_to >expect.body $subtip $subprev-dirty && | |
71 | test_cmp expect.body actual.body | |
72 | ' | |
73 | ||
74 | test_expect_success 'git diff HEAD with dirty submodule (index)' ' | |
75 | ( | |
76 | cd sub && | |
77 | git reset --hard && | |
78 | echo >>world && | |
79 | git add world | |
80 | ) && | |
81 | git diff HEAD >actual && | |
82 | sed -e "1,/^@@/d" actual >actual.body && | |
83 | expect_from_to >expect.body $subtip $subprev-dirty && | |
84 | test_cmp expect.body actual.body | |
85 | ' | |
86 | ||
87 | test_expect_success 'git diff HEAD with dirty submodule (untracked)' ' | |
88 | ( | |
89 | cd sub && | |
90 | git reset --hard && | |
91 | git clean -qfdx && | |
92 | >cruft | |
93 | ) && | |
94 | git diff HEAD >actual && | |
95 | sed -e "1,/^@@/d" actual >actual.body && | |
96 | expect_from_to >expect.body $subtip $subprev-dirty && | |
97 | test_cmp expect.body actual.body | |
98 | ' | |
99 | ||
100 | test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)' ' | |
101 | git commit -m "x" sub && | |
102 | echo >>sub/world && | |
103 | git diff HEAD >actual && | |
104 | sed -e "1,/^@@/d" actual >actual.body && | |
105 | expect_from_to >expect.body $subprev $subprev-dirty && | |
dd44d419 JL |
106 | test_cmp expect.body actual.body && |
107 | git diff --ignore-submodules HEAD >actual2 && | |
ec10b018 | 108 | test_must_be_empty actual2 && |
dd44d419 JL |
109 | git diff --ignore-submodules=untracked HEAD >actual3 && |
110 | sed -e "1,/^@@/d" actual3 >actual3.body && | |
111 | expect_from_to >expect.body $subprev $subprev-dirty && | |
112 | test_cmp expect.body actual3.body && | |
113 | git diff --ignore-submodules=dirty HEAD >actual4 && | |
ec10b018 | 114 | test_must_be_empty actual4 |
8e08b419 | 115 | ' |
6ed7ddaa | 116 | |
302ad7a9 | 117 | test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) [.gitmodules]' ' |
90e14525 JL |
118 | git config diff.ignoreSubmodules dirty && |
119 | git diff HEAD >actual && | |
ec10b018 | 120 | test_must_be_empty actual && |
302ad7a9 JL |
121 | git config --add -f .gitmodules submodule.subname.ignore none && |
122 | git config --add -f .gitmodules submodule.subname.path sub && | |
123 | git diff HEAD >actual && | |
124 | sed -e "1,/^@@/d" actual >actual.body && | |
125 | expect_from_to >expect.body $subprev $subprev-dirty && | |
126 | test_cmp expect.body actual.body && | |
127 | git config -f .gitmodules submodule.subname.ignore all && | |
128 | git config -f .gitmodules submodule.subname.path sub && | |
129 | git diff HEAD >actual2 && | |
ec10b018 | 130 | test_must_be_empty actual2 && |
302ad7a9 JL |
131 | git config -f .gitmodules submodule.subname.ignore untracked && |
132 | git diff HEAD >actual3 && | |
133 | sed -e "1,/^@@/d" actual3 >actual3.body && | |
134 | expect_from_to >expect.body $subprev $subprev-dirty && | |
135 | test_cmp expect.body actual3.body && | |
136 | git config -f .gitmodules submodule.subname.ignore dirty && | |
137 | git diff HEAD >actual4 && | |
ec10b018 | 138 | test_must_be_empty actual4 && |
302ad7a9 JL |
139 | git config submodule.subname.ignore none && |
140 | git config submodule.subname.path sub && | |
141 | git diff HEAD >actual && | |
142 | sed -e "1,/^@@/d" actual >actual.body && | |
143 | expect_from_to >expect.body $subprev $subprev-dirty && | |
144 | test_cmp expect.body actual.body && | |
145 | git config --remove-section submodule.subname && | |
146 | git config --remove-section -f .gitmodules submodule.subname && | |
90e14525 | 147 | git config --unset diff.ignoreSubmodules && |
302ad7a9 JL |
148 | rm .gitmodules |
149 | ' | |
150 | ||
8e08b419 JH |
151 | test_expect_success 'git diff HEAD with dirty submodule (index, refs match)' ' |
152 | ( | |
153 | cd sub && | |
154 | git reset --hard && | |
155 | echo >>world && | |
156 | git add world | |
157 | ) && | |
158 | git diff HEAD >actual && | |
159 | sed -e "1,/^@@/d" actual >actual.body && | |
160 | expect_from_to >expect.body $subprev $subprev-dirty && | |
161 | test_cmp expect.body actual.body | |
162 | ' | |
163 | ||
164 | test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' ' | |
165 | ( | |
166 | cd sub && | |
167 | git reset --hard && | |
168 | git clean -qfdx && | |
169 | >cruft | |
170 | ) && | |
171 | git diff HEAD >actual && | |
172 | sed -e "1,/^@@/d" actual >actual.body && | |
173 | expect_from_to >expect.body $subprev $subprev-dirty && | |
dd44d419 JL |
174 | test_cmp expect.body actual.body && |
175 | git diff --ignore-submodules=all HEAD >actual2 && | |
ec10b018 | 176 | test_must_be_empty actual2 && |
dd44d419 | 177 | git diff --ignore-submodules=untracked HEAD >actual3 && |
ec10b018 | 178 | test_must_be_empty actual3 && |
dd44d419 | 179 | git diff --ignore-submodules=dirty HEAD >actual4 && |
ec10b018 | 180 | test_must_be_empty actual4 |
8e08b419 JH |
181 | ' |
182 | ||
302ad7a9 JL |
183 | test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) [.gitmodules]' ' |
184 | git config --add -f .gitmodules submodule.subname.ignore all && | |
185 | git config --add -f .gitmodules submodule.subname.path sub && | |
186 | git diff HEAD >actual2 && | |
ec10b018 | 187 | test_must_be_empty actual2 && |
302ad7a9 JL |
188 | git config -f .gitmodules submodule.subname.ignore untracked && |
189 | git diff HEAD >actual3 && | |
ec10b018 | 190 | test_must_be_empty actual3 && |
302ad7a9 JL |
191 | git config -f .gitmodules submodule.subname.ignore dirty && |
192 | git diff HEAD >actual4 && | |
ec10b018 | 193 | test_must_be_empty actual4 && |
302ad7a9 JL |
194 | git config submodule.subname.ignore none && |
195 | git config submodule.subname.path sub && | |
196 | git diff HEAD >actual && | |
197 | sed -e "1,/^@@/d" actual >actual.body && | |
198 | expect_from_to >expect.body $subprev $subprev-dirty && | |
199 | test_cmp expect.body actual.body && | |
200 | git config --remove-section submodule.subname && | |
201 | git config --remove-section -f .gitmodules submodule.subname && | |
202 | rm .gitmodules | |
203 | ' | |
204 | ||
aee9c7d6 JL |
205 | test_expect_success 'git diff between submodule commits' ' |
206 | git diff HEAD^..HEAD >actual && | |
207 | sed -e "1,/^@@/d" actual >actual.body && | |
208 | expect_from_to >expect.body $subtip $subprev && | |
209 | test_cmp expect.body actual.body && | |
210 | git diff --ignore-submodules=dirty HEAD^..HEAD >actual && | |
211 | sed -e "1,/^@@/d" actual >actual.body && | |
212 | expect_from_to >expect.body $subtip $subprev && | |
213 | test_cmp expect.body actual.body && | |
214 | git diff --ignore-submodules HEAD^..HEAD >actual && | |
ec10b018 | 215 | test_must_be_empty actual |
aee9c7d6 JL |
216 | ' |
217 | ||
302ad7a9 JL |
218 | test_expect_success 'git diff between submodule commits [.gitmodules]' ' |
219 | git diff HEAD^..HEAD >actual && | |
220 | sed -e "1,/^@@/d" actual >actual.body && | |
221 | expect_from_to >expect.body $subtip $subprev && | |
222 | test_cmp expect.body actual.body && | |
223 | git config --add -f .gitmodules submodule.subname.ignore dirty && | |
224 | git config --add -f .gitmodules submodule.subname.path sub && | |
225 | git diff HEAD^..HEAD >actual && | |
226 | sed -e "1,/^@@/d" actual >actual.body && | |
227 | expect_from_to >expect.body $subtip $subprev && | |
228 | test_cmp expect.body actual.body && | |
229 | git config -f .gitmodules submodule.subname.ignore all && | |
230 | git diff HEAD^..HEAD >actual && | |
ec10b018 | 231 | test_must_be_empty actual && |
302ad7a9 JL |
232 | git config submodule.subname.ignore dirty && |
233 | git config submodule.subname.path sub && | |
234 | git diff HEAD^..HEAD >actual && | |
235 | sed -e "1,/^@@/d" actual >actual.body && | |
236 | expect_from_to >expect.body $subtip $subprev && | |
237 | git config --remove-section submodule.subname && | |
238 | git config --remove-section -f .gitmodules submodule.subname && | |
239 | rm .gitmodules | |
240 | ' | |
241 | ||
1392a377 | 242 | test_expect_success 'git diff (empty submodule dir)' ' |
7c08a2a6 PY |
243 | rm -rf sub/* sub/.git && |
244 | git diff > actual.empty && | |
1c5e94f4 | 245 | test_must_be_empty actual.empty |
7c08a2a6 PY |
246 | ' |
247 | ||
7dae8b21 | 248 | test_expect_success 'conflicted submodule setup' ' |
45e2ef2b | 249 | c=$(test_oid ff_1) && |
7dae8b21 | 250 | ( |
8125a58b | 251 | echo "000000 $ZERO_OID 0 sub" && |
a48fcd83 JN |
252 | echo "160000 1$c 1 sub" && |
253 | echo "160000 2$c 2 sub" && | |
7dae8b21 JH |
254 | echo "160000 3$c 3 sub" |
255 | ) | git update-index --index-info && | |
45e2ef2b | 256 | echo >expect.nosub "diff --cc sub |
7dae8b21 JH |
257 | index 2ffffff,3ffffff..0000000 |
258 | --- a/sub | |
259 | +++ b/sub | |
260 | @@@ -1,1 -1,1 +1,1 @@@ | |
45e2ef2b | 261 | - Subproject commit 2$c |
262 | -Subproject commit 3$c | |
263 | ++Subproject commit $ZERO_OID" && | |
7dae8b21 JH |
264 | |
265 | hh=$(git rev-parse HEAD) && | |
8125a58b | 266 | sed -e "s/$ZERO_OID/$hh/" expect.nosub >expect.withsub |
7dae8b21 JH |
267 | |
268 | ' | |
269 | ||
270 | test_expect_success 'combined (empty submodule)' ' | |
271 | rm -fr sub && mkdir sub && | |
272 | git diff >actual && | |
273 | test_cmp expect.nosub actual | |
274 | ' | |
275 | ||
276 | test_expect_success 'combined (with submodule)' ' | |
277 | rm -fr sub && | |
278 | git clone --no-checkout . sub && | |
279 | git diff >actual && | |
280 | test_cmp expect.withsub actual | |
281 | ' | |
282 | ||
283 | ||
284 | ||
2b459b48 | 285 | test_done |