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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Dec 7, 2020 at 15:19 UTC 469f17d09789e781bee22edf6233f234a2c5afd3
1 file changed +52 -51
t/t7064-wtstatus-pv2.sh
+52 -51
@@ -9,6 +9,7 @@ This test exercises porcelain V2 output for git status.'
9
10
11 test_expect_success setup '
12 + git checkout -f --orphan initial-branch &&
13 test_tick &&
14 git config core.autocrlf false &&
15 echo x >file_x &&
@@ -22,7 +23,7 @@ test_expect_success setup '
23 test_expect_success 'before initial commit, nothing added, only untracked' '
24 cat >expect <<-EOF &&
25 # branch.oid (initial)
25 - # branch.head master
26 + # branch.head initial-branch
27 ? actual
28 ? dir1/
29 ? expect
@@ -45,7 +46,7 @@ test_expect_success 'before initial commit, things added' '
46
47 cat >expect <<-EOF &&
48 # branch.oid (initial)
48 - # branch.head master
49 + # branch.head initial-branch
50 1 A. N... 000000 100644 100644 $ZERO_OID $OID_A dir1/file_a
51 1 A. N... 000000 100644 100644 $ZERO_OID $OID_B dir1/file_b
52 1 A. N... 000000 100644 100644 $ZERO_OID $OID_X file_x
@@ -62,7 +63,7 @@ test_expect_success 'before initial commit, things added' '
63 test_expect_success 'before initial commit, things added (-z)' '
64 lf_to_nul >expect <<-EOF &&
65 # branch.oid (initial)
65 - # branch.head master
66 + # branch.head initial-branch
67 1 A. N... 000000 100644 100644 $ZERO_OID $OID_A dir1/file_a
68 1 A. N... 000000 100644 100644 $ZERO_OID $OID_B dir1/file_b
69 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' '
82 H0=$(git rev-parse HEAD) &&
83 cat >expect <<-EOF &&
84 # branch.oid $H0
84 - # branch.head master
85 + # branch.head initial-branch
86 ? actual
87 ? expect
88 EOF
@@ -98,7 +99,7 @@ test_expect_success 'after first commit, create unstaged changes' '
99
100 cat >expect <<-EOF &&
101 # branch.oid $H0
101 - # branch.head master
102 + # branch.head initial-branch
103 1 .M N... 100644 100644 100644 $OID_X $OID_X file_x
104 1 .D N... 100644 100644 000000 $OID_Z $OID_Z file_z
105 ? actual
@@ -126,7 +127,7 @@ test_expect_success 'after first commit, stage existing changes' '
127
128 cat >expect <<-EOF &&
129 # branch.oid $H0
129 - # branch.head master
130 + # branch.head initial-branch
131 1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x
132 1 D. N... 100644 000000 000000 $OID_Z $ZERO_OID file_z
133 ? actual
@@ -143,7 +144,7 @@ test_expect_success 'rename causes 2 path lines' '
144
145 q_to_tab >expect <<-EOF &&
146 # branch.oid $H0
146 - # branch.head master
147 + # branch.head initial-branch
148 1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x
149 1 D. N... 100644 000000 000000 $OID_Z $ZERO_OID file_z
150 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)' '
162 ## Lines use NUL path separator and line terminator, so double transform here.
163 q_to_nul <<-EOF | lf_to_nul >expect &&
164 # branch.oid $H0
164 - # branch.head master
165 + # branch.head initial-branch
166 1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x
167 1 D. N... 100644 000000 000000 $OID_Z $ZERO_OID file_z
168 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' '
180
181 cat >expect <<-EOF &&
182 # branch.oid $H1
182 - # branch.head master
183 + # branch.head initial-branch
184 ? actual
185 ? expect
186 EOF
@@ -231,7 +232,7 @@ test_expect_success 'create and commit permanent ignore file' '
232
233 cat >expect <<-EOF &&
234 # branch.oid $H1
234 - # branch.head master
235 + # branch.head initial-branch
236 EOF
237
238 git status --porcelain=v2 --branch >actual &&
@@ -257,14 +258,14 @@ test_expect_success 'verify --intent-to-add output' '
258 test_expect_success 'verify AA (add-add) conflict' '
259 test_when_finished "git reset --hard" &&
260
260 - git branch AA_A master &&
261 + git branch AA_A initial-branch &&
262 git checkout AA_A &&
263 echo "Branch AA_A" >conflict.txt &&
264 OID_AA_A=$(git hash-object -t blob -- conflict.txt) &&
265 git add conflict.txt &&
266 git commit -m "branch aa_a" &&
267
267 - git branch AA_B master &&
268 + git branch AA_B initial-branch &&
269 git checkout AA_B &&
270 echo "Branch AA_B" >conflict.txt &&
271 OID_AA_B=$(git hash-object -t blob -- conflict.txt) &&
@@ -290,7 +291,7 @@ test_expect_success 'verify AA (add-add) conflict' '
291 test_expect_success 'verify UU (edit-edit) conflict' '
292 test_when_finished "git reset --hard" &&
293
293 - git branch UU_ANC master &&
294 + git branch UU_ANC initial-branch &&
295 git checkout UU_ANC &&
296 echo "Ancestor" >conflict.txt &&
297 OID_UU_ANC=$(git hash-object -t blob -- conflict.txt) &&
@@ -328,18 +329,18 @@ test_expect_success 'verify UU (edit-edit) conflict' '
329 '
330
331 test_expect_success 'verify upstream fields in branch header' '
331 - git checkout master &&
332 + git checkout initial-branch &&
333 test_when_finished "rm -rf sub_repo" &&
334 git clone . sub_repo &&
335 (
335 - ## Confirm local master tracks remote master.
336 + ## Confirm local initial-branch tracks remote initial-branch.
337 cd sub_repo &&
338 HUF=$(git rev-parse HEAD) &&
339
340 cat >expect <<-EOF &&
341 # branch.oid $HUF
341 - # branch.head master
342 - # branch.upstream origin/master
342 + # branch.head initial-branch
343 + # branch.upstream origin/initial-branch
344 # branch.ab +0 -0
345 EOF
346
@@ -355,8 +356,8 @@ test_expect_success 'verify upstream fields in branch header' '
356
357 cat >expect <<-EOF &&
358 # branch.oid $HUF
358 - # branch.head master
359 - # branch.upstream origin/master
359 + # branch.head initial-branch
360 + # branch.upstream origin/initial-branch
361 # branch.ab +1 -0
362 EOF
363
@@ -367,9 +368,9 @@ test_expect_success 'verify upstream fields in branch header' '
368 git status --porcelain=v2 --untracked-files=all >actual &&
369 test_must_be_empty actual &&
370
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) &&
374 NEW=$ZERO_OID &&
375 mv .git/packed-refs .git/old-packed-refs &&
376 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' '
379
380 cat >expect <<-EOF &&
381 # branch.oid $HUF
381 - # branch.head master
382 - # branch.upstream origin/master
382 + # branch.head initial-branch
383 + # branch.upstream origin/initial-branch
384 EOF
385
386 git status --porcelain=v2 --branch --untracked-files=all >actual &&
@@ -388,19 +389,19 @@ test_expect_success 'verify upstream fields in branch header' '
389 '
390
391 test_expect_success 'verify --[no-]ahead-behind with V2 format' '
391 - git checkout master &&
392 + git checkout initial-branch &&
393 test_when_finished "rm -rf sub_repo" &&
394 git clone . sub_repo &&
395 (
395 - ## Confirm local master tracks remote master.
396 + ## Confirm local initial-branch tracks remote initial-branch.
397 cd sub_repo &&
398 HUF=$(git rev-parse HEAD) &&
399
400 # Confirm --no-ahead-behind reports traditional branch.ab with 0/0 for equal branches.
401 cat >expect <<-EOF &&
402 # branch.oid $HUF
402 - # branch.head master
403 - # branch.upstream origin/master
403 + # branch.head initial-branch
404 + # branch.upstream origin/initial-branch
405 # branch.ab +0 -0
406 EOF
407
@@ -410,8 +411,8 @@ test_expect_success 'verify --[no-]ahead-behind with V2 format' '
411 # Confirm --ahead-behind reports traditional branch.ab with 0/0.
412 cat >expect <<-EOF &&
413 # branch.oid $HUF
413 - # branch.head master
414 - # branch.upstream origin/master
414 + # branch.head initial-branch
415 + # branch.upstream origin/initial-branch
416 # branch.ab +0 -0
417 EOF
418
@@ -428,8 +429,8 @@ test_expect_success 'verify --[no-]ahead-behind with V2 format' '
429 # Confirm --no-ahead-behind reports branch.ab with ?/? for non-equal branches.
430 cat >expect <<-EOF &&
431 # branch.oid $HUF
431 - # branch.head master
432 - # branch.upstream origin/master
432 + # branch.head initial-branch
433 + # branch.upstream origin/initial-branch
434 # branch.ab +? -?
435 EOF
436
@@ -439,8 +440,8 @@ test_expect_success 'verify --[no-]ahead-behind with V2 format' '
440 # Confirm --ahead-behind reports traditional branch.ab with 1/0.
441 cat >expect <<-EOF &&
442 # branch.oid $HUF
442 - # branch.head master
443 - # branch.upstream origin/master
443 + # branch.head initial-branch
444 + # branch.upstream origin/initial-branch
445 # branch.ab +1 -0
446 EOF
447
@@ -458,7 +459,7 @@ test_expect_success 'verify --[no-]ahead-behind with V2 format' '
459 '
460
461 test_expect_success 'create and add submodule, submodule appears clean (A. S...)' '
461 - git checkout master &&
462 + git checkout initial-branch &&
463 git clone . sub_repo &&
464 git clone . super_repo &&
465 ( cd super_repo &&
@@ -471,8 +472,8 @@ test_expect_success 'create and add submodule, submodule appears clean (A. S...)
472
473 cat >expect <<-EOF &&
474 # branch.oid $HSUP
474 - # branch.head master
475 - # branch.upstream origin/master
475 + # branch.head initial-branch
476 + # branch.upstream origin/initial-branch
477 # branch.ab +0 -0
478 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
479 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)' '
497
498 cat >expect <<-EOF &&
499 # branch.oid $HSUP
499 - # branch.head master
500 - # branch.upstream origin/master
500 + # branch.head initial-branch
501 + # branch.upstream origin/initial-branch
502 # branch.ab +0 -0
503 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
504 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.)' '
522
523 cat >expect <<-EOF &&
524 # branch.oid $HSUP
524 - # branch.head master
525 - # branch.upstream origin/master
525 + # branch.head initial-branch
526 + # branch.upstream origin/initial-branch
527 # branch.ab +0 -0
528 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
529 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.)' '
549
550 cat >expect <<-EOF &&
551 # branch.oid $HSUP
551 - # branch.head master
552 - # branch.upstream origin/master
552 + # branch.head initial-branch
553 + # branch.upstream origin/initial-branch
554 # branch.ab +0 -0
555 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
556 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)'
576
577 cat >expect <<-EOF &&
578 # branch.oid $HSUP
578 - # branch.head master
579 - # branch.upstream origin/master
579 + # branch.head initial-branch
580 + # branch.upstream origin/initial-branch
581 # branch.ab +0 -0
582 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
583 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
603
604 cat >expect <<-EOF &&
605 # branch.oid $HSUP
605 - # branch.head master
606 - # branch.upstream origin/master
606 + # branch.head initial-branch
607 + # branch.upstream origin/initial-branch
608 # branch.ab +0 -0
609 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
610 1 AM SC.. 000000 160000 160000 $ZERO_OID $HSUB sub1
@@ -625,8 +626,8 @@ test_expect_success 'stage submodule in super and commit' '
626
627 cat >expect <<-EOF &&
628 # branch.oid $HSUP
628 - # branch.head master
629 - # branch.upstream origin/master
629 + # branch.head initial-branch
630 + # branch.upstream origin/initial-branch
631 # branch.ab +1 -0
632 EOF
633
@@ -646,8 +647,8 @@ test_expect_success 'make unstaged changes in existing submodule (.M S.M.)' '
647
648 cat >expect <<-EOF &&
649 # branch.oid $HSUP
649 - # branch.head master
650 - # branch.upstream origin/master
650 + # branch.head initial-branch
651 + # branch.upstream origin/initial-branch
652 # branch.ab +1 -0
653 1 .M S.M. 160000 160000 160000 $HSUB $HSUB sub1
654 EOF