3 test_description='difference in submodules'
6 . "$TEST_DIRECTORY"/diff-lib.sh
8 _z40=0000000000000000000000000000000000000000
9 test_expect_success setup '
11 test_create_repo sub &&
16 git commit -m submodule
22 git commit -m superproject &&
26 echo goodbye >world &&
28 git commit -m "submodule #2"
35 echo ":160000 160000 $3 $_z40 M sub" >expect &&
39 test_expect_success 'git diff --raw HEAD' '
40 git diff --raw --abbrev=40 HEAD >actual &&
41 test_cmp expect actual
44 test_expect_success 'git diff-index --raw HEAD' '
45 git diff-index --raw HEAD >actual.index &&
46 test_cmp expect actual.index
49 test_expect_success 'git diff-files --raw' '
50 git diff-files --raw >actual.files &&
51 test_cmp expect actual.files
55 printf "%sSubproject commit %s\n+Subproject commit %s\n" \
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
66 test_expect_success 'git diff HEAD with dirty submodule (work tree)' '
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
74 test_expect_success 'git diff HEAD with dirty submodule (index)' '
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
87 test_expect_success 'git diff HEAD with dirty submodule (untracked)' '
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
100 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)' '
101 git commit -m "x" sub &&
103 git diff HEAD >actual &&
104 sed -e "1,/^@@/d" actual >actual.body &&
105 expect_from_to >expect.body $subprev $subprev-dirty &&
106 test_cmp expect.body actual.body &&
107 git diff --ignore-submodules HEAD >actual2 &&
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 &&
117 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) [.git/config]' '
118 git config diff.ignoreSubmodules all &&
119 git diff HEAD >actual &&
121 git config submodule.subname.ignore none &&
122 git config 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 submodule.subname.ignore all &&
128 git diff HEAD >actual2 &&
130 git config submodule.subname.ignore untracked &&
131 git diff HEAD >actual3 &&
132 sed -e "1,/^@@/d" actual3 >actual3.body &&
133 expect_from_to >expect.body $subprev $subprev-dirty &&
134 test_cmp expect.body actual3.body &&
135 git config submodule.subname.ignore dirty &&
136 git diff HEAD >actual4 &&
138 git diff HEAD --ignore-submodules=none >actual &&
139 sed -e "1,/^@@/d" actual >actual.body &&
140 expect_from_to >expect.body $subprev $subprev-dirty &&
141 test_cmp expect.body actual.body &&
142 git config --remove-section submodule.subname &&
143 git config --unset diff.ignoreSubmodules
146 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) [.gitmodules]' '
147 git config diff.ignoreSubmodules dirty &&
148 git diff HEAD >actual &&
150 git config --add -f .gitmodules submodule.subname.ignore none &&
151 git config --add -f .gitmodules submodule.subname.path sub &&
152 git diff HEAD >actual &&
153 sed -e "1,/^@@/d" actual >actual.body &&
154 expect_from_to >expect.body $subprev $subprev-dirty &&
155 test_cmp expect.body actual.body &&
156 git config -f .gitmodules submodule.subname.ignore all &&
157 git config -f .gitmodules submodule.subname.path sub &&
158 git diff HEAD >actual2 &&
160 git config -f .gitmodules submodule.subname.ignore untracked &&
161 git diff HEAD >actual3 &&
162 sed -e "1,/^@@/d" actual3 >actual3.body &&
163 expect_from_to >expect.body $subprev $subprev-dirty &&
164 test_cmp expect.body actual3.body &&
165 git config -f .gitmodules submodule.subname.ignore dirty &&
166 git diff HEAD >actual4 &&
168 git config submodule.subname.ignore none &&
169 git config submodule.subname.path sub &&
170 git diff HEAD >actual &&
171 sed -e "1,/^@@/d" actual >actual.body &&
172 expect_from_to >expect.body $subprev $subprev-dirty &&
173 test_cmp expect.body actual.body &&
174 git config --remove-section submodule.subname &&
175 git config --remove-section -f .gitmodules submodule.subname &&
176 git config --unset diff.ignoreSubmodules &&
180 test_expect_success 'git diff HEAD with dirty submodule (index, refs match)' '
187 git diff HEAD >actual &&
188 sed -e "1,/^@@/d" actual >actual.body &&
189 expect_from_to >expect.body $subprev $subprev-dirty &&
190 test_cmp expect.body actual.body
193 test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' '
200 git diff HEAD >actual &&
201 sed -e "1,/^@@/d" actual >actual.body &&
202 expect_from_to >expect.body $subprev $subprev-dirty &&
203 test_cmp expect.body actual.body &&
204 git diff --ignore-submodules=all HEAD >actual2 &&
206 git diff --ignore-submodules=untracked HEAD >actual3 &&
208 git diff --ignore-submodules=dirty HEAD >actual4 &&
212 test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) [.git/config]' '
213 git config submodule.subname.ignore all &&
214 git config submodule.subname.path sub &&
215 git diff HEAD >actual2 &&
217 git config submodule.subname.ignore untracked &&
218 git diff HEAD >actual3 &&
220 git config submodule.subname.ignore dirty &&
221 git diff HEAD >actual4 &&
223 git diff --ignore-submodules=none HEAD >actual &&
224 sed -e "1,/^@@/d" actual >actual.body &&
225 expect_from_to >expect.body $subprev $subprev-dirty &&
226 test_cmp expect.body actual.body &&
227 git config --remove-section submodule.subname
230 test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) [.gitmodules]' '
231 git config --add -f .gitmodules submodule.subname.ignore all &&
232 git config --add -f .gitmodules submodule.subname.path sub &&
233 git diff HEAD >actual2 &&
235 git config -f .gitmodules submodule.subname.ignore untracked &&
236 git diff HEAD >actual3 &&
238 git config -f .gitmodules submodule.subname.ignore dirty &&
239 git diff HEAD >actual4 &&
241 git config submodule.subname.ignore none &&
242 git config submodule.subname.path sub &&
243 git diff HEAD >actual &&
244 sed -e "1,/^@@/d" actual >actual.body &&
245 expect_from_to >expect.body $subprev $subprev-dirty &&
246 test_cmp expect.body actual.body &&
247 git config --remove-section submodule.subname &&
248 git config --remove-section -f .gitmodules submodule.subname &&
252 test_expect_success 'git diff between submodule commits' '
253 git diff HEAD^..HEAD >actual &&
254 sed -e "1,/^@@/d" actual >actual.body &&
255 expect_from_to >expect.body $subtip $subprev &&
256 test_cmp expect.body actual.body &&
257 git diff --ignore-submodules=dirty HEAD^..HEAD >actual &&
258 sed -e "1,/^@@/d" actual >actual.body &&
259 expect_from_to >expect.body $subtip $subprev &&
260 test_cmp expect.body actual.body &&
261 git diff --ignore-submodules HEAD^..HEAD >actual &&
265 test_expect_success 'git diff between submodule commits [.git/config]' '
266 git diff HEAD^..HEAD >actual &&
267 sed -e "1,/^@@/d" actual >actual.body &&
268 expect_from_to >expect.body $subtip $subprev &&
269 test_cmp expect.body actual.body &&
270 git config submodule.subname.ignore dirty &&
271 git config submodule.subname.path sub &&
272 git diff HEAD^..HEAD >actual &&
273 sed -e "1,/^@@/d" actual >actual.body &&
274 expect_from_to >expect.body $subtip $subprev &&
275 test_cmp expect.body actual.body &&
276 git config submodule.subname.ignore all &&
277 git diff HEAD^..HEAD >actual &&
279 git diff --ignore-submodules=dirty HEAD^..HEAD >actual &&
280 sed -e "1,/^@@/d" actual >actual.body &&
281 expect_from_to >expect.body $subtip $subprev &&
282 git config --remove-section submodule.subname
285 test_expect_success 'git diff between submodule commits [.gitmodules]' '
286 git diff HEAD^..HEAD >actual &&
287 sed -e "1,/^@@/d" actual >actual.body &&
288 expect_from_to >expect.body $subtip $subprev &&
289 test_cmp expect.body actual.body &&
290 git config --add -f .gitmodules submodule.subname.ignore dirty &&
291 git config --add -f .gitmodules submodule.subname.path sub &&
292 git diff HEAD^..HEAD >actual &&
293 sed -e "1,/^@@/d" actual >actual.body &&
294 expect_from_to >expect.body $subtip $subprev &&
295 test_cmp expect.body actual.body &&
296 git config -f .gitmodules submodule.subname.ignore all &&
297 git diff HEAD^..HEAD >actual &&
299 git config submodule.subname.ignore dirty &&
300 git config submodule.subname.path sub &&
301 git diff HEAD^..HEAD >actual &&
302 sed -e "1,/^@@/d" actual >actual.body &&
303 expect_from_to >expect.body $subtip $subprev &&
304 git config --remove-section submodule.subname &&
305 git config --remove-section -f .gitmodules submodule.subname &&
309 test_expect_success 'git diff (empty submodule dir)' '
311 rm -rf sub/* sub/.git &&
312 git diff > actual.empty &&
313 test_cmp empty actual.empty
316 test_expect_success 'conflicted submodule setup' '
319 c=fffffffffffffffffffffffffffffffffffffff
321 echo "000000 $_z40 0 sub"
322 echo "160000 1$c 1 sub"
323 echo "160000 2$c 2 sub"
324 echo "160000 3$c 3 sub"
325 ) | git update-index --index-info &&
326 echo >expect.nosub '\''diff --cc sub
327 index 2ffffff,3ffffff..0000000
330 @@@ -1,1 -1,1 +1,1 @@@
331 - Subproject commit 2fffffffffffffffffffffffffffffffffffffff
332 -Subproject commit 3fffffffffffffffffffffffffffffffffffffff
333 ++Subproject commit 0000000000000000000000000000000000000000'\'' &&
335 hh=$(git rev-parse HEAD) &&
336 sed -e "s/$_z40/$hh/" expect.nosub >expect.withsub
340 test_expect_success 'combined (empty submodule)' '
341 rm -fr sub && mkdir sub &&
343 test_cmp expect.nosub actual
346 test_expect_success 'combined (with submodule)' '
348 git clone --no-checkout . sub &&
350 test_cmp expect.withsub actual