382
test_cmp expect actual
383
'
384
385
+test_expect_success 'git branch -c dumps usage' '
386
+ test_expect_code 128 git branch -c 2>err &&
387
+ test_i18ngrep "branch name required" err
388
+'
389
+
390
+test_expect_success 'git branch --copy dumps usage' '
391
+ test_expect_code 128 git branch --copy 2>err &&
392
+ test_i18ngrep "branch name required" err
393
+'
394
+
395
+test_expect_success 'git branch -c d e should work' '
396
+ git branch -l d &&
397
+ git reflog exists refs/heads/d &&
398
+ git config branch.d.dummy Hello &&
399
+ git branch -c d e &&
400
+ git reflog exists refs/heads/d &&
401
+ git reflog exists refs/heads/e &&
402
+ echo Hello >expect &&
403
+ git config branch.e.dummy >actual &&
404
+ test_cmp expect actual &&
405
+ echo Hello >expect &&
406
+ git config branch.d.dummy >actual &&
407
+ test_cmp expect actual
408
+'
409
+
410
+test_expect_success 'git branch --copy is a synonym for -c' '
411
+ git branch -l copy &&
412
+ git reflog exists refs/heads/copy &&
413
+ git config branch.copy.dummy Hello &&
414
+ git branch --copy copy copy-to &&
415
+ git reflog exists refs/heads/copy &&
416
+ git reflog exists refs/heads/copy-to &&
417
+ echo Hello >expect &&
418
+ git config branch.copy.dummy >actual &&
419
+ test_cmp expect actual &&
420
+ echo Hello >expect &&
421
+ git config branch.copy-to.dummy >actual &&
422
+ test_cmp expect actual
423
+'
424
+
425
+test_expect_success 'git branch -c ee ef should copy and checkout branch ef' '
426
+ git checkout -b ee &&
427
+ git reflog exists refs/heads/ee &&
428
+ git config branch.ee.dummy Hello &&
429
+ git branch -c ee ef &&
430
+ git reflog exists refs/heads/ee &&
431
+ git reflog exists refs/heads/ef &&
432
+ test $(git config branch.ee.dummy) = Hello &&
433
+ test $(git config branch.ef.dummy) = Hello &&
434
+ test $(git rev-parse --abbrev-ref HEAD) = ef
435
+'
436
+
437
+test_expect_success 'git branch -c f/f g/g should work' '
438
+ git branch -l f/f &&
439
+ git reflog exists refs/heads/f/f &&
440
+ git config branch.f/f.dummy Hello &&
441
+ git branch -c f/f g/g &&
442
+ git reflog exists refs/heads/f/f &&
443
+ git reflog exists refs/heads/g/g &&
444
+ test $(git config branch.f/f.dummy) = Hello &&
445
+ test $(git config branch.g/g.dummy) = Hello
446
+'
447
+
448
+test_expect_success 'git branch -c m2 m2 should work' '
449
+ git branch -l m2 &&
450
+ git reflog exists refs/heads/m2 &&
451
+ git config branch.m2.dummy Hello &&
452
+ git branch -c m2 m2 &&
453
+ git reflog exists refs/heads/m2 &&
454
+ test $(git config branch.m2.dummy) = Hello
455
+'
456
+
457
+test_expect_success 'git branch -c zz zz/zz should fail' '
458
+ git branch -l zz &&
459
+ git reflog exists refs/heads/zz &&
460
+ test_must_fail git branch -c zz zz/zz
461
+'
462
+
463
+test_expect_success 'git branch -c b/b b should fail' '
464
+ git branch -l b/b &&
465
+ test_must_fail git branch -c b/b b
466
+'
467
+
468
+test_expect_success 'git branch -C o/q o/p should work when o/p exists' '
469
+ git branch -l o/q &&
470
+ git reflog exists refs/heads/o/q &&
471
+ git reflog exists refs/heads/o/p &&
472
+ git branch -C o/q o/p
473
+'
474
+
475
+test_expect_success 'git branch -c -f o/q o/p should work when o/p exists' '
476
+ git reflog exists refs/heads/o/q &&
477
+ git reflog exists refs/heads/o/p &&
478
+ git branch -c -f o/q o/p
479
+'
480
+
481
+test_expect_success 'git branch -c qq rr/qq should fail when r exists' '
482
+ git branch qq &&
483
+ git branch rr &&
484
+ test_must_fail git branch -c qq rr/qq
485
+'
486
+
487
+test_expect_success 'git branch -C b1 b2 should fail when b2 is checked out' '
488
+ git branch b1 &&
489
+ git checkout -b b2 &&
490
+ test_must_fail git branch -C b1 b2
491
+'
492
+
493
+test_expect_success 'git branch -C c1 c2 should succeed when c1 is checked out' '
494
+ git checkout -b c1 &&
495
+ git branch c2 &&
496
+ git branch -C c1 c2 &&
497
+ test $(git rev-parse --abbrev-ref HEAD) = c2
498
+'
499
+
500
+test_expect_success 'git branch -C c1 c2 should add entries to .git/logs/HEAD' '
501
+ msg="Branch: copied refs/heads/c1 to refs/heads/c2" &&
502
+ grep "$msg$" .git/logs/HEAD
503
+'
504
+
505
+test_expect_success 'git branch -C master should work when master is checked out' '
506
+ git checkout master &&
507
+ git branch -C master
508
+'
509
+
510
+test_expect_success 'git branch -C master master should work when master is checked out' '
511
+ git checkout master &&
512
+ git branch -C master master
513
+'
514
+
515
+test_expect_success 'git branch -C master5 master5 should work when master is checked out' '
516
+ git checkout master &&
517
+ git branch master5 &&
518
+ git branch -C master5 master5
519
+'
520
+
521
+test_expect_success 'git branch -C ab cd should overwrite existing config for cd' '
522
+ git branch -l cd &&
523
+ git reflog exists refs/heads/cd &&
524
+ git config branch.cd.dummy CD &&
525
+ git branch -l ab &&
526
+ git reflog exists refs/heads/ab &&
527
+ git config branch.ab.dummy AB &&
528
+ git branch -C ab cd &&
529
+ git reflog exists refs/heads/ab &&
530
+ git reflog exists refs/heads/cd &&
531
+ test $(git config branch.ab.dummy) = AB &&
532
+ test $(git config branch.cd.dummy) = AB
533
+'
534
+
535
+test_expect_success 'git branch -c correctly copies multiple config sections' '
536
+ FOO=1 &&
537
+ export FOO &&
538
+ test_when_finished "git checkout master" &&
539
+ git checkout -b source2 master &&
540
+
541
+ # Assert that a config file with multiple config sections has
542
+ # those sections preserved...
543
+ cat >expect <<-\EOF &&
544
+ branch.source2.key1=value1
545
+ branch.dest2.key1=value1
546
+ more.gar.b=age
547
+ branch.source2.key2=value2
548
+ branch.dest2.key2=value2
549
+ EOF
550
+ cat >config.branch <<\EOF &&
551
+;; Note the lack of -\EOF above & mixed indenting here. This is
552
+;; intentional, we are also testing that the formatting of copied
553
+;; sections is preserved.
554
+
555
+;; Comment for source2. Tabs
556
+[branch "source2"]
557
+ ;; Comment for the source2 value
558
+ key1 = value1
559
+;; Comment for more.gar. Spaces
560
+[more "gar"]
561
+ ;; Comment for the more.gar value
562
+ b = age
563
+;; Comment for source2, again. Mixed tabs/spaces.
564
+[branch "source2"]
565
+ ;; Comment for the source2 value, again
566
+ key2 = value2
567
+EOF
568
+ cat config.branch >>.git/config &&
569
+ git branch -c source2 dest2 &&
570
+ git config -f .git/config -l | grep -F -e source2 -e dest2 -e more.gar >actual &&
571
+ test_cmp expect actual &&
572
+
573
+ # ...and that the comments and formatting for those sections
574
+ # is also preserved.
575
+ cat >expect <<\EOF &&
576
+;; Comment for source2. Tabs
577
+[branch "source2"]
578
+ ;; Comment for the source2 value
579
+ key1 = value1
580
+;; Comment for more.gar. Spaces
581
+[branch "dest2"]
582
+ ;; Comment for the source2 value
583
+ key1 = value1
584
+;; Comment for more.gar. Spaces
585
+[more "gar"]
586
+ ;; Comment for the more.gar value
587
+ b = age
588
+;; Comment for source2, again. Mixed tabs/spaces.
589
+[branch "source2"]
590
+ ;; Comment for the source2 value, again
591
+ key2 = value2
592
+[branch "dest2"]
593
+ ;; Comment for the source2 value, again
594
+ key2 = value2
595
+EOF
596
+ sed -n -e "/Comment for source2/,\$p" .git/config >actual &&
597
+ test_cmp expect actual
598
+'
599
+
600
test_expect_success 'deleting a symref' '
601
git branch target &&
602
git symbolic-ref refs/heads/symref refs/heads/target &&