t6300: avoid using the default name of the initial branch
Our test suite currently only passes when `git init` uses the name `master` for the initial branch. This would stop us from changing the default branch name. Let's adjust t6300 so that it does not rely on any specific default branch name. This trick is done by (force-)renaming the initial branch to the name `main` in the `setup` and the `:remotename and :remoteref` test cases, and then replacing all mentions of `master` and `MASTER` with `main` and `MAIN`, respectively. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Dec 6, 2020 at 13:15 UTC
8f19c9fd433c02ee1496bc6f34ef0a061c3f2087
1 file changed
+90
-88
t/t6300-for-each-ref.sh
+90
-88
@@ -28,12 +28,13 @@ test_expect_success setup '
28
echo "Using $datestamp" > one &&
29
git add one &&
30
git commit -m "Initial" &&
31
+ git branch -M main &&
32
setdate_and_increment &&
33
git tag -a -m "Tagging at $datestamp" testtag &&
33
- git update-ref refs/remotes/origin/master master &&
34
+ git update-ref refs/remotes/origin/main main &&
35
git remote add origin nowhere &&
35
- git config branch.master.remote origin &&
36
- git config branch.master.merge refs/heads/master &&
36
+ git config branch.main.remote origin &&
37
+ git config branch.main.merge refs/heads/main &&
38
git remote add myfork elsewhere &&
39
git config remote.pushdefault myfork &&
40
git config push.default current
@@ -41,7 +42,7 @@ test_expect_success setup '
42
43
test_atom() {
44
case "$1" in
44
- head) ref=refs/heads/master ;;
45
+ head) ref=refs/heads/main ;;
46
tag) ref=refs/tags/testtag ;;
47
sym) ref=refs/heads/sym ;;
48
*) ref=$1 ;;
@@ -76,49 +77,49 @@ test_atom() {
77
hexlen=$(test_oid hexsz)
78
disklen=$(test_oid disklen)
79
79
-test_atom head refname refs/heads/master
80
-test_atom head refname: refs/heads/master
81
-test_atom head refname:short master
82
-test_atom head refname:lstrip=1 heads/master
83
-test_atom head refname:lstrip=2 master
84
-test_atom head refname:lstrip=-1 master
85
-test_atom head refname:lstrip=-2 heads/master
80
+test_atom head refname refs/heads/main
81
+test_atom head refname: refs/heads/main
82
+test_atom head refname:short main
83
+test_atom head refname:lstrip=1 heads/main
84
+test_atom head refname:lstrip=2 main
85
+test_atom head refname:lstrip=-1 main
86
+test_atom head refname:lstrip=-2 heads/main
87
test_atom head refname:rstrip=1 refs/heads
88
test_atom head refname:rstrip=2 refs
89
test_atom head refname:rstrip=-1 refs
90
test_atom head refname:rstrip=-2 refs/heads
90
-test_atom head refname:strip=1 heads/master
91
-test_atom head refname:strip=2 master
92
-test_atom head refname:strip=-1 master
93
-test_atom head refname:strip=-2 heads/master
94
-test_atom head upstream refs/remotes/origin/master
95
-test_atom head upstream:short origin/master
96
-test_atom head upstream:lstrip=2 origin/master
97
-test_atom head upstream:lstrip=-2 origin/master
91
+test_atom head refname:strip=1 heads/main
92
+test_atom head refname:strip=2 main
93
+test_atom head refname:strip=-1 main
94
+test_atom head refname:strip=-2 heads/main
95
+test_atom head upstream refs/remotes/origin/main
96
+test_atom head upstream:short origin/main
97
+test_atom head upstream:lstrip=2 origin/main
98
+test_atom head upstream:lstrip=-2 origin/main
99
test_atom head upstream:rstrip=2 refs/remotes
100
test_atom head upstream:rstrip=-2 refs/remotes
100
-test_atom head upstream:strip=2 origin/master
101
-test_atom head upstream:strip=-2 origin/master
102
-test_atom head push refs/remotes/myfork/master
103
-test_atom head push:short myfork/master
104
-test_atom head push:lstrip=1 remotes/myfork/master
105
-test_atom head push:lstrip=-1 master
101
+test_atom head upstream:strip=2 origin/main
102
+test_atom head upstream:strip=-2 origin/main
103
+test_atom head push refs/remotes/myfork/main
104
+test_atom head push:short myfork/main
105
+test_atom head push:lstrip=1 remotes/myfork/main
106
+test_atom head push:lstrip=-1 main
107
test_atom head push:rstrip=1 refs/remotes/myfork
108
test_atom head push:rstrip=-1 refs
108
-test_atom head push:strip=1 remotes/myfork/master
109
-test_atom head push:strip=-1 master
109
+test_atom head push:strip=1 remotes/myfork/main
110
+test_atom head push:strip=-1 main
111
test_atom head objecttype commit
112
test_atom head objectsize $((131 + hexlen))
113
test_atom head objectsize:disk $disklen
114
test_atom head deltabase $ZERO_OID
114
-test_atom head objectname $(git rev-parse refs/heads/master)
115
-test_atom head objectname:short $(git rev-parse --short refs/heads/master)
116
-test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master)
117
-test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master)
118
-test_atom head tree $(git rev-parse refs/heads/master^{tree})
119
-test_atom head tree:short $(git rev-parse --short refs/heads/master^{tree})
120
-test_atom head tree:short=1 $(git rev-parse --short=1 refs/heads/master^{tree})
121
-test_atom head tree:short=10 $(git rev-parse --short=10 refs/heads/master^{tree})
115
+test_atom head objectname $(git rev-parse refs/heads/main)
116
+test_atom head objectname:short $(git rev-parse --short refs/heads/main)
117
+test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/main)
118
+test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/main)
119
+test_atom head tree $(git rev-parse refs/heads/main^{tree})
120
+test_atom head tree:short $(git rev-parse --short refs/heads/main^{tree})
121
+test_atom head tree:short=1 $(git rev-parse --short=1 refs/heads/main^{tree})
122
+test_atom head tree:short=10 $(git rev-parse --short=10 refs/heads/main^{tree})
123
test_atom head parent ''
124
test_atom head parent:short ''
125
test_atom head parent:short=1 ''
@@ -171,8 +172,8 @@ test_atom tag deltabase $ZERO_OID
172
test_atom tag '*deltabase' $ZERO_OID
173
test_atom tag objectname $(git rev-parse refs/tags/testtag)
174
test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag)
174
-test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master)
175
-test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master)
175
+test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/main)
176
+test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/main)
177
test_atom tag tree ''
178
test_atom tag tree:short ''
179
test_atom tag tree:short=1 ''
@@ -253,7 +254,7 @@ test_date () {
254
author_date=$3 &&
255
tagger_date=$4 &&
256
cat >expected <<-EOF &&
256
- 'refs/heads/master' '$committer_date' '$author_date'
257
+ 'refs/heads/main' '$committer_date' '$author_date'
258
'refs/tags/testtag' '$tagger_date'
259
EOF
260
(
@@ -375,8 +376,8 @@ test_expect_success 'exercise strftime with odd fields' '
376
'
377
378
cat >expected <<\EOF
378
-refs/heads/master
379
-refs/remotes/origin/master
379
+refs/heads/main
380
+refs/remotes/origin/main
381
refs/tags/testtag
382
EOF
383
@@ -388,8 +389,8 @@ test_expect_success 'Verify ascending sort' '
389
390
cat >expected <<\EOF
391
refs/tags/testtag
391
-refs/remotes/origin/master
392
-refs/heads/master
392
+refs/remotes/origin/main
393
+refs/heads/main
394
EOF
395
396
test_expect_success 'Verify descending sort' '
@@ -424,8 +425,8 @@ test_expect_success 'exercise glob patterns with prefixes' '
425
'
426
427
cat >expected <<\EOF
427
-'refs/heads/master'
428
-'refs/remotes/origin/master'
428
+'refs/heads/main'
429
+'refs/remotes/origin/main'
430
'refs/tags/testtag'
431
EOF
432
@@ -445,8 +446,8 @@ test_expect_success 'Quoting style: python' '
446
'
447
448
cat >expected <<\EOF
448
-"refs/heads/master"
449
-"refs/remotes/origin/master"
449
+"refs/heads/main"
450
+"refs/remotes/origin/main"
451
"refs/tags/testtag"
452
EOF
453
@@ -473,8 +474,8 @@ test_atom head upstream:nobracket,track 'ahead 1'
474
475
test_expect_success 'setup for push:track[short]' '
476
test_commit third &&
476
- git update-ref refs/remotes/myfork/master master &&
477
- git reset master~1
477
+ git update-ref refs/remotes/myfork/main main &&
478
+ git reset main~1
479
'
480
481
test_atom head push:track '[behind 1]'
@@ -490,8 +491,8 @@ test_expect_success 'Check that :track[short] works when upstream is invalid' '
491
[gone]
492
493
EOF
493
- test_when_finished "git config branch.master.merge refs/heads/master" &&
494
- git config branch.master.merge refs/heads/does-not-exist &&
494
+ test_when_finished "git config branch.main.merge refs/heads/main" &&
495
+ git config branch.main.merge refs/heads/does-not-exist &&
496
git for-each-ref \
497
--format="%(upstream:track)$LF%(upstream:trackshort)" \
498
refs/heads >actual &&
@@ -504,9 +505,9 @@ test_expect_success 'Check for invalid refname format' '
505
506
test_expect_success 'set up color tests' '
507
cat >expected.color <<-EOF &&
507
- $(git rev-parse --short refs/heads/master) <GREEN>master<RESET>
508
- $(git rev-parse --short refs/remotes/myfork/master) <GREEN>myfork/master<RESET>
509
- $(git rev-parse --short refs/remotes/origin/master) <GREEN>origin/master<RESET>
508
+ $(git rev-parse --short refs/heads/main) <GREEN>main<RESET>
509
+ $(git rev-parse --short refs/remotes/myfork/main) <GREEN>myfork/main<RESET>
510
+ $(git rev-parse --short refs/remotes/origin/main) <GREEN>origin/main<RESET>
511
$(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET>
512
$(git rev-parse --short refs/tags/third) <GREEN>third<RESET>
513
$(git rev-parse --short refs/tags/two) <GREEN>two<RESET>
@@ -538,8 +539,8 @@ test_expect_success 'color.ui=always does not override tty check' '
539
'
540
541
cat >expected <<\EOF
541
-heads/master
542
-tags/master
542
+heads/main
543
+tags/main
544
EOF
545
546
test_expect_success 'Check ambiguous head and tag refs (strict)' '
@@ -549,19 +550,19 @@ test_expect_success 'Check ambiguous head and tag refs (strict)' '
550
git add one &&
551
git commit -m "Branch" &&
552
setdate_and_increment &&
552
- git tag -m "Tagging at $datestamp" master &&
553
- git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
553
+ git tag -m "Tagging at $datestamp" main &&
554
+ git for-each-ref --format "%(refname:short)" refs/heads/main refs/tags/main >actual &&
555
test_cmp expected actual
556
'
557
558
cat >expected <<\EOF
558
-heads/master
559
-master
559
+heads/main
560
+main
561
EOF
562
563
test_expect_success 'Check ambiguous head and tag refs (loose)' '
564
git config --bool core.warnambiguousrefs false &&
564
- git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
565
+ git for-each-ref --format "%(refname:short)" refs/heads/main refs/tags/main >actual &&
566
test_cmp expected actual
567
'
568
@@ -571,7 +572,7 @@ ambiguous
572
EOF
573
574
test_expect_success 'Check ambiguous head and tag refs II (loose)' '
574
- git checkout master &&
575
+ git checkout main &&
576
git tag ambiguous testtag^0 &&
577
git branch ambiguous testtag^0 &&
578
git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
@@ -705,8 +706,8 @@ body contents
706
$sig"
707
708
test_expect_success 'set up refs pointing to tree and blob' '
708
- git update-ref refs/mytrees/first refs/heads/master^{tree} &&
709
- git update-ref refs/myblobs/first refs/heads/master:one
709
+ git update-ref refs/mytrees/first refs/heads/main^{tree} &&
710
+ git update-ref refs/myblobs/first refs/heads/main:one
711
'
712
713
test_atom refs/mytrees/first subject ""
@@ -778,7 +779,7 @@ test_expect_success 'equivalent sorts fall back on refname' '
779
'
780
781
test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
781
- test_when_finished "git checkout master" &&
782
+ test_when_finished "git checkout main" &&
783
git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
784
sed -e "s/^\* / /" actual >expect &&
785
git checkout --orphan orphaned-branch &&
@@ -815,9 +816,9 @@ test_expect_success '%(trailers:unfold) unfolds trailers' '
816
unfold <trailers
817
echo
818
} >expect &&
818
- git for-each-ref --format="%(trailers:unfold)" refs/heads/master >actual &&
819
+ git for-each-ref --format="%(trailers:unfold)" refs/heads/main >actual &&
820
test_cmp expect actual &&
820
- git for-each-ref --format="%(contents:trailers:unfold)" refs/heads/master >actual &&
821
+ git for-each-ref --format="%(contents:trailers:unfold)" refs/heads/main >actual &&
822
test_cmp expect actual
823
'
824
@@ -826,9 +827,9 @@ test_expect_success '%(trailers:only) shows only "key: value" trailers' '
827
grep -v patch.description <trailers &&
828
echo
829
} >expect &&
829
- git for-each-ref --format="%(trailers:only)" refs/heads/master >actual &&
830
+ git for-each-ref --format="%(trailers:only)" refs/heads/main >actual &&
831
test_cmp expect actual &&
831
- git for-each-ref --format="%(contents:trailers:only)" refs/heads/master >actual &&
832
+ git for-each-ref --format="%(contents:trailers:only)" refs/heads/main >actual &&
833
test_cmp expect actual
834
'
835
@@ -837,13 +838,13 @@ test_expect_success '%(trailers:only) and %(trailers:unfold) work together' '
838
grep -v patch.description <trailers | unfold &&
839
echo
840
} >expect &&
840
- git for-each-ref --format="%(trailers:only,unfold)" refs/heads/master >actual &&
841
+ git for-each-ref --format="%(trailers:only,unfold)" refs/heads/main >actual &&
842
test_cmp expect actual &&
842
- git for-each-ref --format="%(trailers:unfold,only)" refs/heads/master >actual &&
843
+ git for-each-ref --format="%(trailers:unfold,only)" refs/heads/main >actual &&
844
test_cmp actual actual &&
844
- git for-each-ref --format="%(contents:trailers:only,unfold)" refs/heads/master >actual &&
845
+ git for-each-ref --format="%(contents:trailers:only,unfold)" refs/heads/main >actual &&
846
test_cmp expect actual &&
846
- git for-each-ref --format="%(contents:trailers:unfold,only)" refs/heads/master >actual &&
847
+ git for-each-ref --format="%(contents:trailers:unfold,only)" refs/heads/main >actual &&
848
test_cmp actual actual
849
'
850
@@ -867,7 +868,7 @@ test_expect_success 'if arguments, %(contents:trailers) shows error if colon is
868
'
869
870
test_expect_success 'basic atom: head contents:trailers' '
870
- git for-each-ref --format="%(contents:trailers)" refs/heads/master >actual &&
871
+ git for-each-ref --format="%(contents:trailers)" refs/heads/main >actual &&
872
sanitize_pgp <actual >actual.clean &&
873
# git for-each-ref ends with a blank line
874
cat >expect <<-EOF &&
@@ -896,16 +897,16 @@ test_expect_success 'trailer parsing not fooled by --- line' '
897
echo "trailer: right" &&
898
echo
899
} >expect &&
899
- git for-each-ref --format="%(trailers)" refs/heads/master >actual &&
900
+ git for-each-ref --format="%(trailers)" refs/heads/main >actual &&
901
test_cmp expect actual
902
'
903
904
test_expect_success 'Add symbolic ref for the following tests' '
904
- git symbolic-ref refs/heads/sym refs/heads/master
905
+ git symbolic-ref refs/heads/sym refs/heads/main
906
'
907
908
cat >expected <<EOF
908
-refs/heads/master
909
+refs/heads/main
910
EOF
911
912
test_expect_success 'Verify usage of %(symref) atom' '
@@ -914,7 +915,7 @@ test_expect_success 'Verify usage of %(symref) atom' '
915
'
916
917
cat >expected <<EOF
917
-heads/master
918
+heads/main
919
EOF
920
921
test_expect_success 'Verify usage of %(symref:short) atom' '
@@ -923,8 +924,8 @@ test_expect_success 'Verify usage of %(symref:short) atom' '
924
'
925
926
cat >expected <<EOF
926
-master
927
-heads/master
927
+main
928
+heads/main
929
EOF
930
931
test_expect_success 'Verify usage of %(symref:lstrip) atom' '
@@ -953,22 +954,23 @@ test_expect_success ':remotename and :remoteref' '
954
(
955
cd remote-tests &&
956
test_commit initial &&
957
+ git branch -M main &&
958
git remote add from fifth.coffee:blub &&
957
- git config branch.master.remote from &&
958
- git config branch.master.merge refs/heads/stable &&
959
+ git config branch.main.remote from &&
960
+ git config branch.main.merge refs/heads/stable &&
961
git remote add to southridge.audio:repo &&
962
git config remote.to.push "refs/heads/*:refs/heads/pushed/*" &&
961
- git config branch.master.pushRemote to &&
963
+ git config branch.main.pushRemote to &&
964
for pair in "%(upstream)=refs/remotes/from/stable" \
965
"%(upstream:remotename)=from" \
966
"%(upstream:remoteref)=refs/heads/stable" \
965
- "%(push)=refs/remotes/to/pushed/master" \
967
+ "%(push)=refs/remotes/to/pushed/main" \
968
"%(push:remotename)=to" \
967
- "%(push:remoteref)=refs/heads/pushed/master"
969
+ "%(push:remoteref)=refs/heads/pushed/main"
970
do
971
echo "${pair#*=}" >expect &&
972
git for-each-ref --format="${pair%=*}" \
971
- refs/heads/master >actual &&
973
+ refs/heads/main >actual &&
974
test_cmp expect actual
975
done &&
976
git branch push-simple &&
@@ -981,12 +983,12 @@ test_expect_success ':remotename and :remoteref' '
983
'
984
985
test_expect_success 'for-each-ref --ignore-case ignores case' '
984
- git for-each-ref --format="%(refname)" refs/heads/MASTER >actual &&
986
+ git for-each-ref --format="%(refname)" refs/heads/MAIN >actual &&
987
test_must_be_empty actual &&
988
987
- echo refs/heads/master >expect &&
989
+ echo refs/heads/main >expect &&
990
git for-each-ref --format="%(refname)" --ignore-case \
989
- refs/heads/MASTER >actual &&
991
+ refs/heads/MAIN >actual &&
992
test_cmp expect actual
993
'
994