git-p4: add tests demonstrating spec overlay ambiguities
Introduce new tests that look more closely at overlay situations when there are conflicting files. Five of these are broken. Document the brokenness. This is a fundamental problem with how git-p4 only "borrows" a client spec. At some sync operation, a new change can contain a file which is already in the repo or explicitly deleted through another mapping. To sort this out would involve listing all the files in the client spec to find one with a higher priority. While this is not too hard for the initial import, subsequent sync operations would be very costly. Signed-off-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pete Wyckoff committed
Jan 11, 2012 at 18:31 UTC
42d8c2799062bafc538d511a0262f76e23c99421
2 files changed
+392
Documentation/git-p4.txt
+5
@@ -314,6 +314,11 @@ around whitespace. Of the possible wildcards, git-p4 only handles
314
'...', and only when it is at the end of the path. Git-p4 will complain
315
if it encounters an unhandled wildcard.
316
317
+Bugs in the implementation of overlap mappings exist. If multiple depot
318
+paths map through overlays to the same location in the repository,
319
+git-p4 can choose the wrong one. This is hard to solve without
320
+dedicating a client spec just for git-p4.
321
+
322
The name of the client can be given to git-p4 in multiple ways. The
323
variable 'git-p4.client' takes precedence if it exists. Otherwise,
324
normal p4 mechanisms of determining the client are used: environment
t/t9809-git-p4-client-view.sh
+387
@@ -246,6 +246,393 @@ test_expect_success 'quotes on rhs only' '
246
git_verify "cdir 1/file11" "cdir 1/file12"
247
'
248
249
+#
250
+# What happens when two files of the same name are overlayed together?
251
+# The last-listed file should take preference.
252
+#
253
+# //depot
254
+# - dir1
255
+# - file11
256
+# - file12
257
+# - filecollide
258
+# - dir2
259
+# - file21
260
+# - file22
261
+# - filecollide
262
+#
263
+test_expect_success 'overlay collision setup' '
264
+ client_view "//depot/... //client/..." &&
265
+ (
266
+ cd "$cli" &&
267
+ p4 sync &&
268
+ echo dir1/filecollide >dir1/filecollide &&
269
+ p4 add dir1/filecollide &&
270
+ p4 submit -d dir1/filecollide &&
271
+ echo dir2/filecollide >dir2/filecollide &&
272
+ p4 add dir2/filecollide &&
273
+ p4 submit -d dir2/filecollide
274
+ )
275
+'
276
+
277
+test_expect_success 'overlay collision 1 to 2' '
278
+ client_view "//depot/dir1/... //client/..." \
279
+ "+//depot/dir2/... //client/..." &&
280
+ files="file11 file12 file21 file22 filecollide" &&
281
+ echo dir2/filecollide >actual &&
282
+ client_verify $files &&
283
+ test_cmp actual "$cli"/filecollide &&
284
+ test_when_finished cleanup_git &&
285
+ "$GITP4" clone --use-client-spec --dest="$git" //depot &&
286
+ git_verify $files &&
287
+ test_cmp actual "$git"/filecollide
288
+'
289
+
290
+test_expect_failure 'overlay collision 2 to 1' '
291
+ client_view "//depot/dir2/... //client/..." \
292
+ "+//depot/dir1/... //client/..." &&
293
+ files="file11 file12 file21 file22 filecollide" &&
294
+ echo dir1/filecollide >actual &&
295
+ client_verify $files &&
296
+ test_cmp actual "$cli"/filecollide &&
297
+ test_when_finished cleanup_git &&
298
+ "$GITP4" clone --use-client-spec --dest="$git" //depot &&
299
+ git_verify $files &&
300
+ test_cmp actual "$git"/filecollide
301
+'
302
+
303
+test_expect_success 'overlay collision delete 2' '
304
+ client_view "//depot/... //client/..." &&
305
+ (
306
+ cd "$cli" &&
307
+ p4 sync &&
308
+ p4 delete dir2/filecollide &&
309
+ p4 submit -d "remove dir2/filecollide"
310
+ )
311
+'
312
+
313
+# no filecollide, got deleted with dir2
314
+test_expect_failure 'overlay collision 1 to 2, but 2 deleted' '
315
+ client_view "//depot/dir1/... //client/..." \
316
+ "+//depot/dir2/... //client/..." &&
317
+ files="file11 file12 file21 file22" &&
318
+ client_verify $files &&
319
+ test_when_finished cleanup_git &&
320
+ "$GITP4" clone --use-client-spec --dest="$git" //depot &&
321
+ git_verify $files
322
+'
323
+
324
+test_expect_success 'overlay collision update 1' '
325
+ client_view "//depot/dir1/... //client/dir1/..." &&
326
+ (
327
+ cd "$cli" &&
328
+ p4 sync &&
329
+ p4 open dir1/filecollide &&
330
+ echo dir1/filecollide update >dir1/filecollide &&
331
+ p4 submit -d "update dir1/filecollide"
332
+ )
333
+'
334
+
335
+# still no filecollide, dir2 still wins with the deletion even though the
336
+# change to dir1 is more recent
337
+test_expect_failure 'overlay collision 1 to 2, but 2 deleted, then 1 updated' '
338
+ client_view "//depot/dir1/... //client/..." \
339
+ "+//depot/dir2/... //client/..." &&
340
+ files="file11 file12 file21 file22" &&
341
+ client_verify $files &&
342
+ test_when_finished cleanup_git &&
343
+ "$GITP4" clone --use-client-spec --dest="$git" //depot &&
344
+ git_verify $files
345
+'
346
+
347
+test_expect_success 'overlay collision delete filecollides' '
348
+ client_view "//depot/... //client/..." &&
349
+ (
350
+ cd "$cli" &&
351
+ p4 sync &&
352
+ p4 delete dir1/filecollide dir2/filecollide &&
353
+ p4 submit -d "remove filecollides"
354
+ )
355
+'
356
+
357
+#
358
+# Overlays as part of sync, rather than initial checkout:
359
+# 1. add a file in dir1
360
+# 2. sync to include it
361
+# 3. add same file in dir2
362
+# 4. sync, make sure content switches as dir2 has priority
363
+# 5. add another file in dir1
364
+# 6. sync
365
+# 7. add/delete same file in dir2
366
+# 8. sync, make sure it disappears, again dir2 wins
367
+# 9. cleanup
368
+#
369
+# //depot
370
+# - dir1
371
+# - file11
372
+# - file12
373
+# - colA
374
+# - colB
375
+# - dir2
376
+# - file21
377
+# - file22
378
+# - colA
379
+# - colB
380
+#
381
+test_expect_success 'overlay sync: add colA in dir1' '
382
+ client_view "//depot/dir1/... //client/dir1/..." &&
383
+ (
384
+ cd "$cli" &&
385
+ p4 sync &&
386
+ echo dir1/colA >dir1/colA &&
387
+ p4 add dir1/colA &&
388
+ p4 submit -d dir1/colA
389
+ )
390
+'
391
+
392
+test_expect_success 'overlay sync: initial git checkout' '
393
+ client_view "//depot/dir1/... //client/..." \
394
+ "+//depot/dir2/... //client/..." &&
395
+ files="file11 file12 file21 file22 colA" &&
396
+ echo dir1/colA >actual &&
397
+ client_verify $files &&
398
+ test_cmp actual "$cli"/colA &&
399
+ "$GITP4" clone --use-client-spec --dest="$git" //depot &&
400
+ git_verify $files &&
401
+ test_cmp actual "$git"/colA
402
+'
403
+
404
+test_expect_success 'overlay sync: add colA in dir2' '
405
+ client_view "//depot/dir2/... //client/dir2/..." &&
406
+ (
407
+ cd "$cli" &&
408
+ p4 sync &&
409
+ echo dir2/colA >dir2/colA &&
410
+ p4 add dir2/colA &&
411
+ p4 submit -d dir2/colA
412
+ )
413
+'
414
+
415
+test_expect_success 'overlay sync: colA content switch' '
416
+ client_view "//depot/dir1/... //client/..." \
417
+ "+//depot/dir2/... //client/..." &&
418
+ files="file11 file12 file21 file22 colA" &&
419
+ echo dir2/colA >actual &&
420
+ client_verify $files &&
421
+ test_cmp actual "$cli"/colA &&
422
+ (
423
+ cd "$git" &&
424
+ "$GITP4" sync --use-client-spec &&
425
+ git merge --ff-only p4/master
426
+ ) &&
427
+ git_verify $files &&
428
+ test_cmp actual "$git"/colA
429
+'
430
+
431
+test_expect_success 'overlay sync: add colB in dir1' '
432
+ client_view "//depot/dir1/... //client/dir1/..." &&
433
+ (
434
+ cd "$cli" &&
435
+ p4 sync &&
436
+ echo dir1/colB >dir1/colB &&
437
+ p4 add dir1/colB &&
438
+ p4 submit -d dir1/colB
439
+ )
440
+'
441
+
442
+test_expect_success 'overlay sync: colB appears' '
443
+ client_view "//depot/dir1/... //client/..." \
444
+ "+//depot/dir2/... //client/..." &&
445
+ files="file11 file12 file21 file22 colA colB" &&
446
+ echo dir1/colB >actual &&
447
+ client_verify $files &&
448
+ test_cmp actual "$cli"/colB &&
449
+ (
450
+ cd "$git" &&
451
+ "$GITP4" sync --use-client-spec &&
452
+ git merge --ff-only p4/master
453
+ ) &&
454
+ git_verify $files &&
455
+ test_cmp actual "$git"/colB
456
+'
457
+
458
+test_expect_success 'overlay sync: add/delete colB in dir2' '
459
+ client_view "//depot/dir2/... //client/dir2/..." &&
460
+ (
461
+ cd "$cli" &&
462
+ p4 sync &&
463
+ echo dir2/colB >dir2/colB &&
464
+ p4 add dir2/colB &&
465
+ p4 submit -d dir2/colB &&
466
+ p4 delete dir2/colB &&
467
+ p4 submit -d "delete dir2/colB"
468
+ )
469
+'
470
+
471
+test_expect_success 'overlay sync: colB disappears' '
472
+ client_view "//depot/dir1/... //client/..." \
473
+ "+//depot/dir2/... //client/..." &&
474
+ files="file11 file12 file21 file22 colA" &&
475
+ client_verify $files &&
476
+ test_when_finished cleanup_git &&
477
+ (
478
+ cd "$git" &&
479
+ "$GITP4" sync --use-client-spec &&
480
+ git merge --ff-only p4/master
481
+ ) &&
482
+ git_verify $files
483
+'
484
+
485
+test_expect_success 'overlay sync: cleanup' '
486
+ client_view "//depot/... //client/..." &&
487
+ (
488
+ cd "$cli" &&
489
+ p4 sync &&
490
+ p4 delete dir1/colA dir2/colA dir1/colB &&
491
+ p4 submit -d "remove overlay sync files"
492
+ )
493
+'
494
+
495
+#
496
+# Overlay tests again, but swapped so dir1 has priority.
497
+# 1. add a file in dir1
498
+# 2. sync to include it
499
+# 3. add same file in dir2
500
+# 4. sync, make sure content does not switch
501
+# 5. add another file in dir1
502
+# 6. sync
503
+# 7. add/delete same file in dir2
504
+# 8. sync, make sure it is still there
505
+# 9. cleanup
506
+#
507
+# //depot
508
+# - dir1
509
+# - file11
510
+# - file12
511
+# - colA
512
+# - colB
513
+# - dir2
514
+# - file21
515
+# - file22
516
+# - colA
517
+# - colB
518
+#
519
+test_expect_success 'overlay sync swap: add colA in dir1' '
520
+ client_view "//depot/dir1/... //client/dir1/..." &&
521
+ (
522
+ cd "$cli" &&
523
+ p4 sync &&
524
+ echo dir1/colA >dir1/colA &&
525
+ p4 add dir1/colA &&
526
+ p4 submit -d dir1/colA
527
+ )
528
+'
529
+
530
+test_expect_success 'overlay sync swap: initial git checkout' '
531
+ client_view "//depot/dir2/... //client/..." \
532
+ "+//depot/dir1/... //client/..." &&
533
+ files="file11 file12 file21 file22 colA" &&
534
+ echo dir1/colA >actual &&
535
+ client_verify $files &&
536
+ test_cmp actual "$cli"/colA &&
537
+ "$GITP4" clone --use-client-spec --dest="$git" //depot &&
538
+ git_verify $files &&
539
+ test_cmp actual "$git"/colA
540
+'
541
+
542
+test_expect_success 'overlay sync swap: add colA in dir2' '
543
+ client_view "//depot/dir2/... //client/dir2/..." &&
544
+ (
545
+ cd "$cli" &&
546
+ p4 sync &&
547
+ echo dir2/colA >dir2/colA &&
548
+ p4 add dir2/colA &&
549
+ p4 submit -d dir2/colA
550
+ )
551
+'
552
+
553
+test_expect_failure 'overlay sync swap: colA no content switch' '
554
+ client_view "//depot/dir2/... //client/..." \
555
+ "+//depot/dir1/... //client/..." &&
556
+ files="file11 file12 file21 file22 colA" &&
557
+ echo dir1/colA >actual &&
558
+ client_verify $files &&
559
+ test_cmp actual "$cli"/colA &&
560
+ (
561
+ cd "$git" &&
562
+ "$GITP4" sync --use-client-spec &&
563
+ git merge --ff-only p4/master
564
+ ) &&
565
+ git_verify $files &&
566
+ test_cmp actual "$git"/colA
567
+'
568
+
569
+test_expect_success 'overlay sync swap: add colB in dir1' '
570
+ client_view "//depot/dir1/... //client/dir1/..." &&
571
+ (
572
+ cd "$cli" &&
573
+ p4 sync &&
574
+ echo dir1/colB >dir1/colB &&
575
+ p4 add dir1/colB &&
576
+ p4 submit -d dir1/colB
577
+ )
578
+'
579
+
580
+test_expect_success 'overlay sync swap: colB appears' '
581
+ client_view "//depot/dir2/... //client/..." \
582
+ "+//depot/dir1/... //client/..." &&
583
+ files="file11 file12 file21 file22 colA colB" &&
584
+ echo dir1/colB >actual &&
585
+ client_verify $files &&
586
+ test_cmp actual "$cli"/colB &&
587
+ (
588
+ cd "$git" &&
589
+ "$GITP4" sync --use-client-spec &&
590
+ git merge --ff-only p4/master
591
+ ) &&
592
+ git_verify $files &&
593
+ test_cmp actual "$git"/colB
594
+'
595
+
596
+test_expect_success 'overlay sync swap: add/delete colB in dir2' '
597
+ client_view "//depot/dir2/... //client/dir2/..." &&
598
+ (
599
+ cd "$cli" &&
600
+ p4 sync &&
601
+ echo dir2/colB >dir2/colB &&
602
+ p4 add dir2/colB &&
603
+ p4 submit -d dir2/colB &&
604
+ p4 delete dir2/colB &&
605
+ p4 submit -d "delete dir2/colB"
606
+ )
607
+'
608
+
609
+test_expect_failure 'overlay sync swap: colB no change' '
610
+ client_view "//depot/dir2/... //client/..." \
611
+ "+//depot/dir1/... //client/..." &&
612
+ files="file11 file12 file21 file22 colA colB" &&
613
+ echo dir1/colB >actual &&
614
+ client_verify $files &&
615
+ test_cmp actual "$cli"/colB &&
616
+ test_when_finished cleanup_git &&
617
+ (
618
+ cd "$git" &&
619
+ "$GITP4" sync --use-client-spec &&
620
+ git merge --ff-only p4/master
621
+ ) &&
622
+ git_verify $files &&
623
+ test_cmp actual "$cli"/colB
624
+'
625
+
626
+test_expect_success 'overlay sync swap: cleanup' '
627
+ client_view "//depot/... //client/..." &&
628
+ (
629
+ cd "$cli" &&
630
+ p4 sync &&
631
+ p4 delete dir1/colA dir2/colA dir1/colB &&
632
+ p4 submit -d "remove overlay sync files"
633
+ )
634
+'
635
+
636
#
637
# Rename directories to test quoting in depot-side mappings
638
# //depot