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