blob 60f6987f9555396fb5509d436cba76c2d9e688c7 11620 bytes (raw)
name: t/t2013-checkout-submodule.sh # note: path name is non-authoritative(*)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
| | #!/bin/sh
test_description='checkout can handle submodules'
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-submodule-update.sh
test_expect_success 'setup' '
mkdir submodule &&
(
cd submodule &&
git init &&
test_commit first
) &&
echo first >file &&
git add file submodule &&
test_tick &&
git commit -m superproject &&
(
cd submodule &&
test_commit second
) &&
echo second > file &&
git add file submodule &&
test_tick &&
git commit -m updated.superproject
'
test_expect_success '"reset <submodule>" updates the index' '
git update-index --refresh &&
git diff-files --quiet &&
git diff-index --quiet --cached HEAD &&
git reset HEAD^ submodule &&
test_must_fail git diff-files --quiet &&
git reset submodule &&
git diff-files --quiet
'
test_expect_success '"checkout <submodule>" updates the index only' '
git update-index --refresh &&
git diff-files --quiet &&
git diff-index --quiet --cached HEAD &&
git checkout HEAD^ submodule &&
test_must_fail git diff-files --quiet &&
git checkout HEAD submodule &&
git diff-files --quiet &&
git diff-index --quiet --cached HEAD
'
test_expect_success '"checkout <submodule>" honors diff.ignoreSubmodules' '
git config diff.ignoreSubmodules dirty &&
echo x> submodule/untracked &&
git checkout HEAD >actual 2>&1 &&
! test -s actual
'
test_expect_success '"checkout <submodule>" honors submodule.*.ignore from .gitmodules' '
git config diff.ignoreSubmodules none &&
git config -f .gitmodules submodule.submodule.path submodule &&
git config -f .gitmodules submodule.submodule.ignore untracked &&
git checkout HEAD >actual 2>&1 &&
! test -s actual
'
test_expect_success '"checkout <submodule>" honors submodule.*.ignore from .git/config' '
git config -f .gitmodules submodule.submodule.ignore none &&
git config submodule.submodule.path submodule &&
git config submodule.submodule.ignore all &&
git checkout HEAD >actual 2>&1 &&
! test -s actual
'
# TODO: hardcode $2
# use flag instead of checking for directory.
submodule_creation_must_succeed() {
# checkout base ($1)
git checkout -f --recurse-submodules $1 &&
git diff-files --quiet &&
git diff-index --quiet --cached $1 &&
# checkout target ($2)
if test -d submodule; then
echo change >>submodule/first.t &&
test_must_fail git checkout --recurse-submodules $2 &&
git checkout -f --recurse-submodules $2
else
git checkout --recurse-submodules $2
fi &&
test -e submodule/.git &&
test -f submodule/first.t &&
test -f submodule/second.t &&
git diff-files --quiet &&
git diff-index --quiet --cached $2
}
# TODO: inline this:
submodule_removal_must_succeed() {
# checkout base ($1)
git checkout -f --recurse-submodules $1 &&
git submodule update -f . &&
test -e submodule/.git &&
git diff-files --quiet &&
git diff-index --quiet --cached $1 &&
# checkout target ($2)
echo change >>submodule/first.t &&
test_must_fail git checkout --recurse-submodules $2 &&
git checkout -f --recurse-submodules $2 &&
git diff-files --quiet &&
git diff-index --quiet --cached $2 &&
! test -d submodule
}
test_expect_success '"check --recurse-submodules" removes deleted submodule' '
# first some setup:
git config -f .gitmodules submodule.submodule.path submodule &&
git config -f .gitmodules submodule.submodule.url ./submodule.bare &&
git -C submodule clone --bare . ../submodule.bare &&
echo submodule.bare >>.gitignore &&
git add .gitignore .gitmodules submodule &&
git commit -m "submodule registered with a gitmodules file" &&
# for testing this case, do it in a fresh clone with the submodules
# git dir inside the superprojects .git/modules dir.
git clone --recurse-submodules . super &&
(
cd super &&
git checkout -b base &&
git checkout -b delete_submodule &&
rm -rf submodule &&
git rm submodule &&
git commit -m "submodule deleted" &&
submodule_removal_must_succeed base delete_submodule
)
'
test_expect_success '"checkout --recurse-submodules" does not delete submodule with .git dir inside' '
git fetch super delete_submodule &&
git checkout --recurse-submodules FETCH_HEAD 2>output.err &&
test_i18ngrep "cannot remove submodule" output.err &&
test -d submodule/.git
'
test_expect_success '"checkout --recurse-submodules" repopulates submodule' '
(
cd super &&
submodule_creation_must_succeed delete_submodule base
)
'
test_expect_success '"checkout --recurse-submodules" repopulates submodule in existing directory' '
(
cd super &&
git checkout --recurse-submodules delete_submodule &&
mkdir submodule &&
submodule_creation_must_succeed delete_submodule base
)
'
test_expect_success '"checkout --recurse-submodules" replaces submodule with files' '
(
cd super
git checkout -f base &&
git checkout -b replace_submodule_with_file &&
git rm -f submodule &&
echo "file instead" >submodule &&
git add submodule &&
git commit -m "submodule replaced" &&
git checkout -f base &&
git submodule update -f . &&
git checkout --recurse-submodules replace_submodule_with_file &&
test -f submodule
)
'
test_expect_success '"checkout --recurse-submodules" removes files and repopulates submodule' '
(
cd super &&
submodule_creation_must_succeed replace_submodule_with_file base
)
'
test_expect_success '"checkout --recurse-submodules" replaces submodule with a directory' '
(
cd super
git checkout -f base &&
git checkout -b replace_submodule_with_dir &&
git rm -f submodule &&
mkdir -p submodule/dir &&
echo content >submodule/dir/file &&
git add submodule &&
git commit -m "submodule replaced with a directory (file inside)" &&
git checkout -f base &&
git submodule update -f . &&
git checkout --recurse-submodules replace_submodule_with_dir &&
test -d submodule &&
! test -e submodule/.git &&
! test -f submodule/first.t &&
! test -f submodule/second.t &&
test -d submodule/dir
)
'
test_expect_success '"checkout --recurse-submodules" removes the directory and repopulates submodule' '
(
cd super
submodule_creation_must_succeed replace_submodule_with_dir base
)
'
test_expect_success SYMLINKS '"checkout --recurse-submodules" replaces submodule with a link' '
(
cd super
git checkout -f base &&
git checkout -b replace_submodule_with_link &&
git rm -f submodule &&
ln -s submodule &&
git add submodule &&
git commit -m "submodule replaced with a link" &&
git checkout -f base &&
git submodule update -f . &&
git checkout --recurse-submodules replace_submodule_with_link &&
test -L submodule
)
'
test_expect_success SYMLINKS '"checkout --recurse-submodules" removes the link and repopulates submodule' '
(
cd super
submodule_creation_must_succeed replace_submodule_with_link base
)
'
test_expect_success '"checkout --recurse-submodules" updates the submodule' '
(
cd super
git checkout --recurse-submodules base &&
git diff-files --quiet &&
git diff-index --quiet --cached HEAD &&
git checkout -b updated_submodule &&
(
cd submodule &&
echo x >>first.t &&
git add first.t &&
test_commit third
) &&
git add submodule &&
test_tick &&
git commit -m updated.superproject &&
git checkout --recurse-submodules base &&
git diff-files --quiet &&
git diff-index --quiet --cached HEAD
)
'
test_expect_failure 'untracked file is not deleted' '
(
cd super &&
git checkout --recurse-submodules base &&
echo important >submodule/untracked &&
test_must_fail git checkout --recurse-submodules delete_submodule &&
git checkout -f --recurse-submodules delete_submodule
)
'
test_expect_success 'ignored file works just fine' '
(
cd super &&
git checkout --recurse-submodules base &&
echo important >submodule/ignored &&
echo ignored >.git/modules/submodule/info/exclude &&
git checkout --recurse-submodules delete_submodule
)
'
test_expect_success 'dirty file file is not deleted' '
(
cd super &&
git checkout --recurse-submodules base &&
echo important >submodule/first.t &&
test_must_fail git checkout --recurse-submodules delete_submodule &&
git checkout -f --recurse-submodules delete_submodule
)
'
test_expect_success 'added to index is not deleted' '
(
cd super &&
git checkout --recurse-submodules base &&
echo important >submodule/to_index &&
git -C submodule add to_index &&
test_must_fail git checkout --recurse-submodules delete_submodule &&
git checkout -f --recurse-submodules delete_submodule
)
'
# This is ok in theory, we just need to make sure
# the garbage collection doesn't eat the commit.
test_expect_success 'different commit prevents from deleting' '
(
cd super &&
git checkout --recurse-submodules base &&
echo important >submodule/to_index &&
git -C submodule add to_index &&
test_must_fail git checkout --recurse-submodules delete_submodule &&
git checkout -f --recurse-submodules delete_submodule
)
'
test_expect_failure '"checkout --recurse-submodules" needs -f to update a modifed submodule commit' '
(
cd submodule &&
git checkout --recurse-submodules HEAD^
) &&
test_must_fail git checkout --recurse-submodules master &&
test_must_fail git diff-files --quiet submodule &&
git diff-files --quiet file &&
git checkout --recurse-submodules -f master &&
git diff-files --quiet &&
git diff-index --quiet --cached HEAD
'
test_expect_failure '"checkout --recurse-submodules" needs -f to update modifed submodule content' '
echo modified >submodule/second.t &&
test_must_fail git checkout --recurse-submodules HEAD^ &&
test_must_fail git diff-files --quiet submodule &&
git diff-files --quiet file &&
git checkout --recurse-submodules -f HEAD^ &&
git diff-files --quiet &&
git diff-index --quiet --cached HEAD &&
git checkout --recurse-submodules -f master &&
git diff-files --quiet &&
git diff-index --quiet --cached HEAD
'
test_expect_failure '"checkout --recurse-submodules" ignores modified submodule content that would not be changed' '
echo modified >expected &&
cp expected submodule/first.t &&
git checkout --recurse-submodules HEAD^ &&
test_cmp expected submodule/first.t &&
test_must_fail git diff-files --quiet submodule &&
git diff-index --quiet --cached HEAD &&
git checkout --recurse-submodules -f master &&
git diff-files --quiet &&
git diff-index --quiet --cached HEAD
'
test_expect_failure '"checkout --recurse-submodules" does not care about untracked submodule content' '
echo untracked >submodule/untracked &&
git checkout --recurse-submodules master &&
git diff-files --quiet --ignore-submodules=untracked &&
git diff-index --quiet --cached HEAD &&
rm submodule/untracked
'
test_expect_failure '"checkout --recurse-submodules" needs -f when submodule commit is not present (but does fail anyway)' '
git checkout --recurse-submodules -b bogus_commit master &&
git update-index --cacheinfo 160000 0123456789012345678901234567890123456789 submodule &&
BOGUS_TREE=$(git write-tree) &&
BOGUS_COMMIT=$(echo "bogus submodule commit" | git commit-tree $BOGUS_TREE) &&
git commit -m "bogus submodule commit" &&
git checkout --recurse-submodules -f master &&
test_must_fail git checkout --recurse-submodules bogus_commit &&
git diff-files --quiet &&
test_must_fail git checkout --recurse-submodules -f bogus_commit &&
test_must_fail git diff-files --quiet submodule &&
git diff-files --quiet file &&
git diff-index --quiet --cached HEAD &&
git checkout --recurse-submodules -f master
'
KNOWN_FAILURE_RECURSE_SUBMODULE_SERIES_BREAKS_REPLACE_SUBMODULE_TEST=1
test_submodule_switch "git checkout"
KNOWN_FAILURE_RECURSE_SUBMODULE_SERIES_BREAKS_REPLACE_SUBMODULE_TEST=
test_submodule_forced_switch "git checkout -f"
test_done
|
debug log:
solving 60f6987 ...
found 60f6987 in http://public-inbox.org/git/20161115230651.23953-15-sbeller@google.com/
found 6847f75 in https://80x24.org/mirrors/git.git
preparing index
index prepared:
100755 6847f7582234d656563f867976a64142a3a01621 t/t2013-checkout-submodule.sh
applying [1/1] http://public-inbox.org/git/20161115230651.23953-15-sbeller@google.com/
diff --git a/t/t2013-checkout-submodule.sh b/t/t2013-checkout-submodule.sh
index 6847f75..60f6987 100755
Checking patch t/t2013-checkout-submodule.sh...
Applied patch t/t2013-checkout-submodule.sh cleanly.
index at:
100755 60f6987f9555396fb5509d436cba76c2d9e688c7 t/t2013-checkout-submodule.sh
(*) Git path names are given by the tree(s) the blob belongs to.
Blobs themselves have no identifier aside from the hash of its contents.^
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).