File: test-git-submodules.t

package info (click to toggle)
hg-git 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,244 kB
  • sloc: python: 8,702; sh: 185; makefile: 23
file content (448 lines) | stat: -rw-r--r-- 15,004 bytes parent folder | download
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
Load commonly used test logic
  $ . "$TESTDIR/testutil"

  $ git init gitrepo1
  Initialized empty Git repository in $TESTTMP/gitrepo1/.git/
  $ cd gitrepo1
  $ echo alpha > alpha
  $ git add alpha
  $ fn_git_commit -m 'add alpha'
  $ cd ..

  $ git init gitsubrepo
  Initialized empty Git repository in $TESTTMP/gitsubrepo/.git/
  $ cd gitsubrepo
  $ echo beta > beta
  $ git add beta
  $ fn_git_commit -m 'add beta'
  $ cd ..

  $ mkdir gitrepo2
  $ cd gitrepo2

  $ rmpwd="import sys; print(sys.stdin.read().replace('$(dirname $(pwd))/', ''))"
different versions of git spell the dir differently. Older versions
use the full path to the directory all the time, whereas newer
version spell it sanely as it was given (eg . in a newer version,
while older git will use the full normalized path for .)
  $ clonefilt='s/Cloning into/Initialized empty Git repository in/;s/in .*/in .../'

  $ git clone ../gitrepo1 . 2>&1 | python -c "$rmpwd" | sed "$clonefilt" | grep -E -v '^done\.$'
  Initialized empty Git repository in ...
  
  $ git submodule add ../gitsubrepo subrepo 2>&1 | python -c "$rmpwd" | sed "$clonefilt" | grep -E -v '^done\.$'
  Initialized empty Git repository in ...
  
  $ git commit -m 'add subrepo' | sed 's/, 0 deletions(-)//'
  [master e42b08b] add subrepo
   2 files changed, 4 insertions(+)
   create mode 100644 .gitmodules
   create mode 160000 subrepo
  $ cd subrepo
  $ echo gamma > gamma
  $ git add gamma
  $ fn_git_commit -m 'add gamma'
  $ cd ..
  $ git add subrepo
  $ git commit -m 'change subrepo commit'
  [master a000567] change subrepo commit
   1 file changed, 1 insertion(+), 1 deletion(-)

  $ git submodule add ../gitsubrepo subrepo2 2>&1 | python -c "$rmpwd" | sed "$clonefilt" | grep -E -v '^done\.$'
  Initialized empty Git repository in ...
  
  $ git commit -m 'add another subrepo' | sed 's/, 0 deletions(-)//'
  [master 6e21952] add another subrepo
   2 files changed, 4 insertions(+)
   create mode 160000 subrepo2

remove one subrepo, replace with file

  $ git rm --cached subrepo
  rm 'subrepo'
we'd ordinarily use sed here, but BSD sed doesn't support two-address formats
like +2 -- so use grep with the stuff we want to keep
  $ grep 'submodule "subrepo2"' -A2 .gitmodules > .gitmodules-new
  $ mv .gitmodules-new .gitmodules
  $ git add .gitmodules
  $ git config --unset submodule.subrepo.url
  $ rm -rf subrepo
  $ echo subrepo > subrepo
  $ git add subrepo
  $ git commit -m 'replace subrepo with file' | sed 's/, 0 deletions(-)//' | sed 's/, 0 insertions(+)//'
  [master f6436a4] replace subrepo with file
   2 files changed, 1 insertion(+), 4 deletions(-)
   mode change 160000 => 100644 subrepo

replace file with subrepo -- apparently, git complains about the subrepo if the
same name has existed at any point historically, so use alpha instead of subrepo

  $ git rm alpha
  rm 'alpha'
  $ git submodule add ../gitsubrepo alpha 2>&1 | python -c "$rmpwd" | sed "$clonefilt" | grep -E -v '^done\.$'
  Initialized empty Git repository in ...
  
  $ git commit -m 'replace file with subrepo' | sed 's/, 0 deletions(-)//' | sed 's/, 0 insertions(+)//'
  [master 8817116] replace file with subrepo
   2 files changed, 4 insertions(+), 1 deletion(-)
   mode change 100644 => 160000 alpha

  $ ln -s foo foolink
  $ git add foolink
  $ git commit -m 'add symlink'
  [master 2d1c135] add symlink
   1 file changed, 1 insertion(+)
   create mode 120000 foolink

replace symlink with subrepo

  $ git rm foolink
  rm 'foolink'
  $ git submodule add ../gitsubrepo foolink 2>&1 | python -c "$rmpwd" | sed "$clonefilt" | grep -E -v '^done\.$'
  Initialized empty Git repository in ...
  
  $ git commit -m 'replace symlink with subrepo' | sed 's/, 0 deletions(-)//' | sed 's/, 0 insertions(+)//'
  [master e3288fa] replace symlink with subrepo
   2 files changed, 4 insertions(+), 1 deletion(-)
   mode change 120000 => 160000 foolink

replace subrepo with symlink

  $ cat > .gitmodules <<EOF
  > [submodule "subrepo2"]
  > 	path = subrepo2
  > 	url = ../gitsubrepo
  > [submodule "alpha"]
  > 	path = alpha
  > 	url = ../gitsubrepo
  > EOF
  $ git add .gitmodules
  $ git rm --cached foolink
  rm 'foolink'
  $ rm -rf foolink
  $ ln -s foo foolink
  $ git add foolink
  $ git commit -m 'replace subrepo with symlink' | sed 's/, 0 deletions(-)//' | sed 's/, 0 insertions(+)//'
  [master d283640] replace subrepo with symlink
   2 files changed, 1 insertion(+), 4 deletions(-)
   mode change 160000 => 120000 foolink
  $ git show
  commit d28364013fe1a0fde56c0e1921e49ecdeee8571d
  Author: test <test@example.org>
  Date:   Mon Jan 1 00:00:12 2007 +0000
  
      replace subrepo with symlink
  
  diff --git a/.gitmodules b/.gitmodules
  index b511494..813e20b 100644
  --- a/.gitmodules
  +++ b/.gitmodules
  @@ -4,6 +4,3 @@
   [submodule "alpha"]
   	path = alpha
   	url = ../gitsubrepo
  -[submodule "foolink"]
  -	path = foolink
  -	url = ../gitsubrepo
  diff --git a/foolink b/foolink
  deleted file mode 160000
  index 6e4ad8d..0000000
  --- a/foolink
  +++ /dev/null
  @@ -1 +0,0 @@
  -Subproject commit 6e4ad8da50204560c00fa25e4987eb2e239029ba
  diff --git a/foolink b/foolink
  new file mode 120000
  index 0000000..1910281
  --- /dev/null
  +++ b/foolink
  @@ -0,0 +1 @@
  +foo
  \ No newline at end of file

  $ git rm --cached subrepo2
  rm 'subrepo2'
  $ git rm --cached alpha
  rm 'alpha'
  $ git rm .gitmodules
  rm '.gitmodules'
  $ git commit -m 'remove all subrepos' | sed 's/, 0 deletions(-)//' | sed 's/, 0 insertions(+)//'
  [master 15ba949] remove all subrepos
   3 files changed, 8 deletions(-)
   delete mode 100644 .gitmodules
   delete mode 160000 alpha
   delete mode 160000 subrepo2

  $ git log --pretty=oneline
  15ba94929481c654814178aac1dbca06ae688718 remove all subrepos
  d28364013fe1a0fde56c0e1921e49ecdeee8571d replace subrepo with symlink
  e3288fa737d429a60637b3b6782cb25b8298bc00 replace symlink with subrepo
  2d1c135447d11df4dfe96dd5d4f37926dc5c821d add symlink
  88171163bf4795b5570924e51d5f8ede33f8bc28 replace file with subrepo
  f6436a472da00f581d8d257e9bbaf3c358a5e88c replace subrepo with file
  6e219527869fa40eb6ffbdd013cd86d576b26b01 add another subrepo
  a000567ceefbd9a2ce364e0dea6e298010b02b6d change subrepo commit
  e42b08b3cb7069b4594a4ee1d9cb641ee47b2355 add subrepo
  7eeab2ea75ec1ac0ff3d500b5b6f8a3447dd7c03 add alpha

  $ cd ..

  $ hg clone gitrepo2 hgrepo
  importing 10 git commits
  new changesets ff7a2f2d8d70:0ad944b2c4d8 (10 drafts)
  updating to bookmark master
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ cd hgrepo
  $ hg log --graph
  @  changeset:   9:0ad944b2c4d8
  |  bookmark:    master
  |  tag:         default/master
  |  tag:         tip
  |  user:        test <test@example.org>
  |  date:        Mon Jan 01 00:00:12 2007 +0000
  |  summary:     remove all subrepos
  |
  o  changeset:   8:33da452ef22f
  |  user:        test <test@example.org>
  |  date:        Mon Jan 01 00:00:12 2007 +0000
  |  summary:     replace subrepo with symlink
  |
  o  changeset:   7:acebec53c0fc
  |  user:        test <test@example.org>
  |  date:        Mon Jan 01 00:00:12 2007 +0000
  |  summary:     replace symlink with subrepo
  |
  o  changeset:   6:78c2ea52db4b
  |  user:        test <test@example.org>
  |  date:        Mon Jan 01 00:00:12 2007 +0000
  |  summary:     add symlink
  |
  o  changeset:   5:c0d52ffc59b8
  |  user:        test <test@example.org>
  |  date:        Mon Jan 01 00:00:12 2007 +0000
  |  summary:     replace file with subrepo
  |
  o  changeset:   4:73e078a178a0
  |  user:        test <test@example.org>
  |  date:        Mon Jan 01 00:00:12 2007 +0000
  |  summary:     replace subrepo with file
  |
  o  changeset:   3:29e236ba4c06
  |  user:        test <test@example.org>
  |  date:        Mon Jan 01 00:00:12 2007 +0000
  |  summary:     add another subrepo
  |
  o  changeset:   2:a6075a162f62
  |  user:        test <test@example.org>
  |  date:        Mon Jan 01 00:00:12 2007 +0000
  |  summary:     change subrepo commit
  |
  o  changeset:   1:a4036e758995
  |  user:        test <test@example.org>
  |  date:        Mon Jan 01 00:00:11 2007 +0000
  |  summary:     add subrepo
  |
  o  changeset:   0:ff7a2f2d8d70
     user:        test <test@example.org>
     date:        Mon Jan 01 00:00:10 2007 +0000
     summary:     add alpha
  
  $ hg book
   * master                    9:0ad944b2c4d8

(add subrepo)
  $ hg cat -r 1 .hgsubstate
  6e4ad8da50204560c00fa25e4987eb2e239029ba subrepo
  $ hg cat -r 1 .hgsub
  subrepo = [git]../gitsubrepo
  $ hg gverify -r 1
  verifying rev a4036e758995 against git commit e42b08b3cb7069b4594a4ee1d9cb641ee47b2355

(change subrepo commit)
  $ hg cat -r 2 .hgsubstate
  aa2ead20c29b5cc6256408e1d9ef704870033afb subrepo
  $ hg cat -r 2 .hgsub
  subrepo = [git]../gitsubrepo
  $ hg gverify -r 2
  verifying rev a6075a162f62 against git commit a000567ceefbd9a2ce364e0dea6e298010b02b6d

(add another subrepo)
  $ hg cat -r 3 .hgsubstate
  aa2ead20c29b5cc6256408e1d9ef704870033afb subrepo
  6e4ad8da50204560c00fa25e4987eb2e239029ba subrepo2
  $ hg cat -r 3 .hgsub
  subrepo = [git]../gitsubrepo
  subrepo2 = [git]../gitsubrepo
  $ hg gverify -r 3
  verifying rev 29e236ba4c06 against git commit 6e219527869fa40eb6ffbdd013cd86d576b26b01

(replace subrepo with file)
  $ hg cat -r 4 .hgsubstate
  6e4ad8da50204560c00fa25e4987eb2e239029ba subrepo2
  $ hg cat -r 4 .hgsub
  subrepo2 = [git]../gitsubrepo
  $ hg manifest -r 4
  .hgsub
  .hgsubstate
  alpha
  subrepo
  $ hg gverify -r 4
  verifying rev 73e078a178a0 against git commit f6436a472da00f581d8d257e9bbaf3c358a5e88c

(replace file with subrepo)
  $ hg cat -r 5 .hgsubstate
  6e4ad8da50204560c00fa25e4987eb2e239029ba alpha
  6e4ad8da50204560c00fa25e4987eb2e239029ba subrepo2
  $ hg cat -r 5 .hgsub
  subrepo2 = [git]../gitsubrepo
  alpha = [git]../gitsubrepo
  $ hg manifest -r 5
  .hgsub
  .hgsubstate
  subrepo
  $ hg gverify -r 5
  verifying rev c0d52ffc59b8 against git commit 88171163bf4795b5570924e51d5f8ede33f8bc28

(replace symlink with subrepo)
  $ hg cat -r 7 .hgsub
  subrepo2 = [git]../gitsubrepo
  alpha = [git]../gitsubrepo
  foolink = [git]../gitsubrepo
  $ hg cat -r 7 .hgsubstate
  6e4ad8da50204560c00fa25e4987eb2e239029ba alpha
  6e4ad8da50204560c00fa25e4987eb2e239029ba foolink
  6e4ad8da50204560c00fa25e4987eb2e239029ba subrepo2
  $ hg gverify -r 7
  verifying rev acebec53c0fc against git commit e3288fa737d429a60637b3b6782cb25b8298bc00

(replace subrepo with symlink)
  $ hg cat -r 8 .hgsub .hgsubstate
  subrepo2 = [git]../gitsubrepo
  alpha = [git]../gitsubrepo
  6e4ad8da50204560c00fa25e4987eb2e239029ba alpha
  6e4ad8da50204560c00fa25e4987eb2e239029ba subrepo2

  $ hg gverify -r 8
  verifying rev 33da452ef22f against git commit d28364013fe1a0fde56c0e1921e49ecdeee8571d

(remove all subrepos)
  $ hg cat -r 9 .hgsub .hgsubstate
  .hgsub: no such file in rev 0ad944b2c4d8
  .hgsubstate: no such file in rev 0ad944b2c4d8
  [1]
  $ hg gverify -r 9
  verifying rev 0ad944b2c4d8 against git commit 15ba94929481c654814178aac1dbca06ae688718

  $ hg debug-remove-hggit-state
  clearing out the git cache data
  $ hg gexport
  $ cd .hg/git
  $ git log --pretty=oneline
  73c15b74fb81fa0cc60e9c59c73787a9f26c778b remove all subrepos
  d28364013fe1a0fde56c0e1921e49ecdeee8571d replace subrepo with symlink
  e3288fa737d429a60637b3b6782cb25b8298bc00 replace symlink with subrepo
  2d1c135447d11df4dfe96dd5d4f37926dc5c821d add symlink
  88171163bf4795b5570924e51d5f8ede33f8bc28 replace file with subrepo
  f6436a472da00f581d8d257e9bbaf3c358a5e88c replace subrepo with file
  6e219527869fa40eb6ffbdd013cd86d576b26b01 add another subrepo
  a000567ceefbd9a2ce364e0dea6e298010b02b6d change subrepo commit
  e42b08b3cb7069b4594a4ee1d9cb641ee47b2355 add subrepo
  7eeab2ea75ec1ac0ff3d500b5b6f8a3447dd7c03 add alpha

test with rename detection enabled -- simply checking that the Mercurial hashes
are the same is enough
  $ cd ../../..
  $ hg --config git.similarity=100 clone gitrepo2 hgreporenames
  importing 10 git commits
  new changesets ff7a2f2d8d70:0ad944b2c4d8 (10 drafts)
  updating to bookmark master
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ cd hgreporenames
  $ hg log --graph
  @  changeset:   9:0ad944b2c4d8
  |  bookmark:    master
  |  tag:         default/master
  |  tag:         tip
  |  user:        test <test@example.org>
  |  date:        Mon Jan 01 00:00:12 2007 +0000
  |  summary:     remove all subrepos
  |
  o  changeset:   8:33da452ef22f
  |  user:        test <test@example.org>
  |  date:        Mon Jan 01 00:00:12 2007 +0000
  |  summary:     replace subrepo with symlink
  |
  o  changeset:   7:acebec53c0fc
  |  user:        test <test@example.org>
  |  date:        Mon Jan 01 00:00:12 2007 +0000
  |  summary:     replace symlink with subrepo
  |
  o  changeset:   6:78c2ea52db4b
  |  user:        test <test@example.org>
  |  date:        Mon Jan 01 00:00:12 2007 +0000
  |  summary:     add symlink
  |
  o  changeset:   5:c0d52ffc59b8
  |  user:        test <test@example.org>
  |  date:        Mon Jan 01 00:00:12 2007 +0000
  |  summary:     replace file with subrepo
  |
  o  changeset:   4:73e078a178a0
  |  user:        test <test@example.org>
  |  date:        Mon Jan 01 00:00:12 2007 +0000
  |  summary:     replace subrepo with file
  |
  o  changeset:   3:29e236ba4c06
  |  user:        test <test@example.org>
  |  date:        Mon Jan 01 00:00:12 2007 +0000
  |  summary:     add another subrepo
  |
  o  changeset:   2:a6075a162f62
  |  user:        test <test@example.org>
  |  date:        Mon Jan 01 00:00:12 2007 +0000
  |  summary:     change subrepo commit
  |
  o  changeset:   1:a4036e758995
  |  user:        test <test@example.org>
  |  date:        Mon Jan 01 00:00:11 2007 +0000
  |  summary:     add subrepo
  |
  o  changeset:   0:ff7a2f2d8d70
     user:        test <test@example.org>
     date:        Mon Jan 01 00:00:10 2007 +0000
     summary:     add alpha
  
  $ cd ..

test handling of an invalid .gitmodules file (#380)

  $ git init --quiet gitrepo-issue380
  $ cd gitrepo-issue380
  $ git submodule add ../gitsubrepo
  Cloning into '$TESTTMP/gitrepo-issue380/gitsubrepo'...
  done.
  $ fn_git_commit -m 'add a submodule'
  $ cat >> .gitmodules <<EOF
  > <<<<<<< HEAD
  > EOF
  $ fn_git_commit -a -m 'b0rken .gitmodules'
  $ git status
  fatal: bad config line 4 in file $TESTTMP/gitrepo-issue380/.gitmodules
  [128]
  $ sed -i.orig /HEAD/d .gitmodules
  $ fn_git_commit -a -m 'fix .gitmodules'
  $ git status
  On branch master
  Untracked files:
    (use "git add <file>..." to include in what will be committed)
  	.gitmodules.orig
  
  nothing added to commit but untracked files present (use "git add" to track)
  $ cd ..
  $ git clone gitrepo-issue380  gitrepo-issue380~
  Cloning into 'gitrepo-issue380~'...
  done.
  $ hg clone -U gitrepo-issue380 hgrepo-issue380
  importing 3 git commits
  warning: failed to parse .gitmodules in 2e4ec4293822
  new changesets ed60e5fbc192:9dfc0cdf1787 (3 drafts)