Skip to content

Commit 469f17d

Browse files
dschogitster
authored andcommitted
t7064: avoid relying on a specific default branch name
To allow us to consider a change in the default behavior of `git init` where it uses a more inclusive name for the initial branch, we must first teach the test suite not to rely on a specific default branch name. In this patch, we teach t7064 that trick. To that end, we set a specific name for the initial branch. Ideally, we would simply start out by calling `git branch -M initial-branch`, but there is a bug in `git branch -M` that does not allow renaming branches unless they already have commits. This will be fixed in the `js/init-defaultbranch-advice` topic, and until that time, we use the equivalent (but less intuitive) `git checkout -f --orphan`. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3a0b884 commit 469f17d

File tree

1 file changed

+52
-51
lines changed

1 file changed

+52
-51
lines changed

t/t7064-wtstatus-pv2.sh

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This test exercises porcelain V2 output for git status.'
99

1010

1111
test_expect_success setup '
12+
git checkout -f --orphan initial-branch &&
1213
test_tick &&
1314
git config core.autocrlf false &&
1415
echo x >file_x &&
@@ -22,7 +23,7 @@ test_expect_success setup '
2223
test_expect_success 'before initial commit, nothing added, only untracked' '
2324
cat >expect <<-EOF &&
2425
# branch.oid (initial)
25-
# branch.head master
26+
# branch.head initial-branch
2627
? actual
2728
? dir1/
2829
? expect
@@ -45,7 +46,7 @@ test_expect_success 'before initial commit, things added' '
4546
4647
cat >expect <<-EOF &&
4748
# branch.oid (initial)
48-
# branch.head master
49+
# branch.head initial-branch
4950
1 A. N... 000000 100644 100644 $ZERO_OID $OID_A dir1/file_a
5051
1 A. N... 000000 100644 100644 $ZERO_OID $OID_B dir1/file_b
5152
1 A. N... 000000 100644 100644 $ZERO_OID $OID_X file_x
@@ -62,7 +63,7 @@ test_expect_success 'before initial commit, things added' '
6263
test_expect_success 'before initial commit, things added (-z)' '
6364
lf_to_nul >expect <<-EOF &&
6465
# branch.oid (initial)
65-
# branch.head master
66+
# branch.head initial-branch
6667
1 A. N... 000000 100644 100644 $ZERO_OID $OID_A dir1/file_a
6768
1 A. N... 000000 100644 100644 $ZERO_OID $OID_B dir1/file_b
6869
1 A. N... 000000 100644 100644 $ZERO_OID $OID_X file_x
@@ -81,7 +82,7 @@ test_expect_success 'make first commit, comfirm HEAD oid and branch' '
8182
H0=$(git rev-parse HEAD) &&
8283
cat >expect <<-EOF &&
8384
# branch.oid $H0
84-
# branch.head master
85+
# branch.head initial-branch
8586
? actual
8687
? expect
8788
EOF
@@ -98,7 +99,7 @@ test_expect_success 'after first commit, create unstaged changes' '
9899
99100
cat >expect <<-EOF &&
100101
# branch.oid $H0
101-
# branch.head master
102+
# branch.head initial-branch
102103
1 .M N... 100644 100644 100644 $OID_X $OID_X file_x
103104
1 .D N... 100644 100644 000000 $OID_Z $OID_Z file_z
104105
? actual
@@ -126,7 +127,7 @@ test_expect_success 'after first commit, stage existing changes' '
126127
127128
cat >expect <<-EOF &&
128129
# branch.oid $H0
129-
# branch.head master
130+
# branch.head initial-branch
130131
1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x
131132
1 D. N... 100644 000000 000000 $OID_Z $ZERO_OID file_z
132133
? actual
@@ -143,7 +144,7 @@ test_expect_success 'rename causes 2 path lines' '
143144
144145
q_to_tab >expect <<-EOF &&
145146
# branch.oid $H0
146-
# branch.head master
147+
# branch.head initial-branch
147148
1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x
148149
1 D. N... 100644 000000 000000 $OID_Z $ZERO_OID file_z
149150
2 R. N... 100644 100644 100644 $OID_Y $OID_Y R100 renamed_yQfile_y
@@ -161,7 +162,7 @@ test_expect_success 'rename causes 2 path lines (-z)' '
161162
## Lines use NUL path separator and line terminator, so double transform here.
162163
q_to_nul <<-EOF | lf_to_nul >expect &&
163164
# branch.oid $H0
164-
# branch.head master
165+
# branch.head initial-branch
165166
1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x
166167
1 D. N... 100644 000000 000000 $OID_Z $ZERO_OID file_z
167168
2 R. N... 100644 100644 100644 $OID_Y $OID_Y R100 renamed_yQfile_y
@@ -179,7 +180,7 @@ test_expect_success 'make second commit, confirm clean and new HEAD oid' '
179180
180181
cat >expect <<-EOF &&
181182
# branch.oid $H1
182-
# branch.head master
183+
# branch.head initial-branch
183184
? actual
184185
? expect
185186
EOF
@@ -231,7 +232,7 @@ test_expect_success 'create and commit permanent ignore file' '
231232
232233
cat >expect <<-EOF &&
233234
# branch.oid $H1
234-
# branch.head master
235+
# branch.head initial-branch
235236
EOF
236237
237238
git status --porcelain=v2 --branch >actual &&
@@ -257,14 +258,14 @@ test_expect_success 'verify --intent-to-add output' '
257258
test_expect_success 'verify AA (add-add) conflict' '
258259
test_when_finished "git reset --hard" &&
259260
260-
git branch AA_A master &&
261+
git branch AA_A initial-branch &&
261262
git checkout AA_A &&
262263
echo "Branch AA_A" >conflict.txt &&
263264
OID_AA_A=$(git hash-object -t blob -- conflict.txt) &&
264265
git add conflict.txt &&
265266
git commit -m "branch aa_a" &&
266267
267-
git branch AA_B master &&
268+
git branch AA_B initial-branch &&
268269
git checkout AA_B &&
269270
echo "Branch AA_B" >conflict.txt &&
270271
OID_AA_B=$(git hash-object -t blob -- conflict.txt) &&
@@ -290,7 +291,7 @@ test_expect_success 'verify AA (add-add) conflict' '
290291
test_expect_success 'verify UU (edit-edit) conflict' '
291292
test_when_finished "git reset --hard" &&
292293
293-
git branch UU_ANC master &&
294+
git branch UU_ANC initial-branch &&
294295
git checkout UU_ANC &&
295296
echo "Ancestor" >conflict.txt &&
296297
OID_UU_ANC=$(git hash-object -t blob -- conflict.txt) &&
@@ -328,18 +329,18 @@ test_expect_success 'verify UU (edit-edit) conflict' '
328329
'
329330

330331
test_expect_success 'verify upstream fields in branch header' '
331-
git checkout master &&
332+
git checkout initial-branch &&
332333
test_when_finished "rm -rf sub_repo" &&
333334
git clone . sub_repo &&
334335
(
335-
## Confirm local master tracks remote master.
336+
## Confirm local initial-branch tracks remote initial-branch.
336337
cd sub_repo &&
337338
HUF=$(git rev-parse HEAD) &&
338339
339340
cat >expect <<-EOF &&
340341
# branch.oid $HUF
341-
# branch.head master
342-
# branch.upstream origin/master
342+
# branch.head initial-branch
343+
# branch.upstream origin/initial-branch
343344
# branch.ab +0 -0
344345
EOF
345346
@@ -355,8 +356,8 @@ test_expect_success 'verify upstream fields in branch header' '
355356
356357
cat >expect <<-EOF &&
357358
# branch.oid $HUF
358-
# branch.head master
359-
# branch.upstream origin/master
359+
# branch.head initial-branch
360+
# branch.upstream origin/initial-branch
360361
# branch.ab +1 -0
361362
EOF
362363
@@ -367,9 +368,9 @@ test_expect_success 'verify upstream fields in branch header' '
367368
git status --porcelain=v2 --untracked-files=all >actual &&
368369
test_must_be_empty actual &&
369370
370-
## Test upstream-gone case. Fake this by pointing origin/master at
371-
## a non-existing commit.
372-
OLD=$(git rev-parse origin/master) &&
371+
## Test upstream-gone case. Fake this by pointing
372+
## origin/initial-branch at a non-existing commit.
373+
OLD=$(git rev-parse origin/initial-branch) &&
373374
NEW=$ZERO_OID &&
374375
mv .git/packed-refs .git/old-packed-refs &&
375376
sed "s/$OLD/$NEW/g" <.git/old-packed-refs >.git/packed-refs &&
@@ -378,8 +379,8 @@ test_expect_success 'verify upstream fields in branch header' '
378379
379380
cat >expect <<-EOF &&
380381
# branch.oid $HUF
381-
# branch.head master
382-
# branch.upstream origin/master
382+
# branch.head initial-branch
383+
# branch.upstream origin/initial-branch
383384
EOF
384385
385386
git status --porcelain=v2 --branch --untracked-files=all >actual &&
@@ -388,19 +389,19 @@ test_expect_success 'verify upstream fields in branch header' '
388389
'
389390

390391
test_expect_success 'verify --[no-]ahead-behind with V2 format' '
391-
git checkout master &&
392+
git checkout initial-branch &&
392393
test_when_finished "rm -rf sub_repo" &&
393394
git clone . sub_repo &&
394395
(
395-
## Confirm local master tracks remote master.
396+
## Confirm local initial-branch tracks remote initial-branch.
396397
cd sub_repo &&
397398
HUF=$(git rev-parse HEAD) &&
398399
399400
# Confirm --no-ahead-behind reports traditional branch.ab with 0/0 for equal branches.
400401
cat >expect <<-EOF &&
401402
# branch.oid $HUF
402-
# branch.head master
403-
# branch.upstream origin/master
403+
# branch.head initial-branch
404+
# branch.upstream origin/initial-branch
404405
# branch.ab +0 -0
405406
EOF
406407
@@ -410,8 +411,8 @@ test_expect_success 'verify --[no-]ahead-behind with V2 format' '
410411
# Confirm --ahead-behind reports traditional branch.ab with 0/0.
411412
cat >expect <<-EOF &&
412413
# branch.oid $HUF
413-
# branch.head master
414-
# branch.upstream origin/master
414+
# branch.head initial-branch
415+
# branch.upstream origin/initial-branch
415416
# branch.ab +0 -0
416417
EOF
417418
@@ -428,8 +429,8 @@ test_expect_success 'verify --[no-]ahead-behind with V2 format' '
428429
# Confirm --no-ahead-behind reports branch.ab with ?/? for non-equal branches.
429430
cat >expect <<-EOF &&
430431
# branch.oid $HUF
431-
# branch.head master
432-
# branch.upstream origin/master
432+
# branch.head initial-branch
433+
# branch.upstream origin/initial-branch
433434
# branch.ab +? -?
434435
EOF
435436
@@ -439,8 +440,8 @@ test_expect_success 'verify --[no-]ahead-behind with V2 format' '
439440
# Confirm --ahead-behind reports traditional branch.ab with 1/0.
440441
cat >expect <<-EOF &&
441442
# branch.oid $HUF
442-
# branch.head master
443-
# branch.upstream origin/master
443+
# branch.head initial-branch
444+
# branch.upstream origin/initial-branch
444445
# branch.ab +1 -0
445446
EOF
446447
@@ -458,7 +459,7 @@ test_expect_success 'verify --[no-]ahead-behind with V2 format' '
458459
'
459460

460461
test_expect_success 'create and add submodule, submodule appears clean (A. S...)' '
461-
git checkout master &&
462+
git checkout initial-branch &&
462463
git clone . sub_repo &&
463464
git clone . super_repo &&
464465
( cd super_repo &&
@@ -471,8 +472,8 @@ test_expect_success 'create and add submodule, submodule appears clean (A. S...)
471472
472473
cat >expect <<-EOF &&
473474
# branch.oid $HSUP
474-
# branch.head master
475-
# branch.upstream origin/master
475+
# branch.head initial-branch
476+
# branch.upstream origin/initial-branch
476477
# branch.ab +0 -0
477478
1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
478479
1 A. S... 000000 160000 160000 $ZERO_OID $HSUB sub1
@@ -496,8 +497,8 @@ test_expect_success 'untracked changes in added submodule (AM S..U)' '
496497
497498
cat >expect <<-EOF &&
498499
# branch.oid $HSUP
499-
# branch.head master
500-
# branch.upstream origin/master
500+
# branch.head initial-branch
501+
# branch.upstream origin/initial-branch
501502
# branch.ab +0 -0
502503
1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
503504
1 AM S..U 000000 160000 160000 $ZERO_OID $HSUB sub1
@@ -521,8 +522,8 @@ test_expect_success 'staged changes in added submodule (AM S.M.)' '
521522
522523
cat >expect <<-EOF &&
523524
# branch.oid $HSUP
524-
# branch.head master
525-
# branch.upstream origin/master
525+
# branch.head initial-branch
526+
# branch.upstream origin/initial-branch
526527
# branch.ab +0 -0
527528
1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
528529
1 AM S.M. 000000 160000 160000 $ZERO_OID $HSUB sub1
@@ -548,8 +549,8 @@ test_expect_success 'staged and unstaged changes in added (AM S.M.)' '
548549
549550
cat >expect <<-EOF &&
550551
# branch.oid $HSUP
551-
# branch.head master
552-
# branch.upstream origin/master
552+
# branch.head initial-branch
553+
# branch.upstream origin/initial-branch
553554
# branch.ab +0 -0
554555
1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
555556
1 AM S.M. 000000 160000 160000 $ZERO_OID $HSUB sub1
@@ -575,8 +576,8 @@ test_expect_success 'staged and untracked changes in added submodule (AM S.MU)'
575576
576577
cat >expect <<-EOF &&
577578
# branch.oid $HSUP
578-
# branch.head master
579-
# branch.upstream origin/master
579+
# branch.head initial-branch
580+
# branch.upstream origin/initial-branch
580581
# branch.ab +0 -0
581582
1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
582583
1 AM S.MU 000000 160000 160000 $ZERO_OID $HSUB sub1
@@ -602,8 +603,8 @@ test_expect_success 'commit within the submodule appears as new commit in super
602603
603604
cat >expect <<-EOF &&
604605
# branch.oid $HSUP
605-
# branch.head master
606-
# branch.upstream origin/master
606+
# branch.head initial-branch
607+
# branch.upstream origin/initial-branch
607608
# branch.ab +0 -0
608609
1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
609610
1 AM SC.. 000000 160000 160000 $ZERO_OID $HSUB sub1
@@ -625,8 +626,8 @@ test_expect_success 'stage submodule in super and commit' '
625626
626627
cat >expect <<-EOF &&
627628
# branch.oid $HSUP
628-
# branch.head master
629-
# branch.upstream origin/master
629+
# branch.head initial-branch
630+
# branch.upstream origin/initial-branch
630631
# branch.ab +1 -0
631632
EOF
632633
@@ -646,8 +647,8 @@ test_expect_success 'make unstaged changes in existing submodule (.M S.M.)' '
646647
647648
cat >expect <<-EOF &&
648649
# branch.oid $HSUP
649-
# branch.head master
650-
# branch.upstream origin/master
650+
# branch.head initial-branch
651+
# branch.upstream origin/initial-branch
651652
# branch.ab +1 -0
652653
1 .M S.M. 160000 160000 160000 $HSUB $HSUB sub1
653654
EOF

0 commit comments

Comments
 (0)