Skip to content

Commit 704fed9

Browse files
dschogitster
authored andcommitted
tests: start moving to a different default main branch name
To allow for an incremental conversion to a new default main branch name, let's introduce `GIT_TEST_DEFAULT_MAIN_BRANCH_NAME`. This environment variable can be set at the top of each converted test script, overriding the default main branch name to use when initializing new repositories (or cloning empty repositories). Note: the `GIT_TEST_DEFAULT_MAIN_BRANCH_NAME` is _not_ intended to be used manually; many tests require a specific main branch name and cannot simply work with another one. This `GIT_TEST_*` variable is meant purely for the transitional period while the entire test suite is converted to use `main` as the initial branch name by default. We also introduce the `PREPARE_FOR_MAIN_BRANCH` prereq that determines whether the default main branch name is `main`, and adjust a couple of test functions to use it. This prereq will be used to temporarily disable a couple test cases to allow for adjusting the test script incrementally. Once an entire test is adjusted, we will adjust the test so that it is run with `GIT_TEST_DEFAULT_MAIN_BRANCH_NAME=main`. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 25ad0dc commit 704fed9

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

refs.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,11 @@ char *repo_default_branch_name(struct repository *r)
567567
const char *config_key = "init.defaultbranch";
568568
const char *config_display_key = "init.defaultBranch";
569569
char *ret = NULL, *full_ref;
570+
const char *env = getenv("GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME");
570571

571-
if (repo_config_get_string(r, config_key, &ret) < 0)
572+
if (env && *env)
573+
ret = xstrdup(env);
574+
else if (repo_config_get_string(r, config_key, &ret) < 0)
572575
die(_("could not retrieve `%s`"), config_display_key);
573576

574577
if (!ret)

t/lib-submodule-update.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ create_lib_submodule_repo () {
144144
git checkout -b valid_sub1 &&
145145
git revert HEAD &&
146146

147-
git checkout master
147+
git checkout "${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}"
148148
)
149149
}
150150

t/t0001-init.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,14 +553,21 @@ test_expect_success '--initial-branch' '
553553

554554
test_expect_success 'overridden default initial branch name (config)' '
555555
test_config_global init.defaultBranch nmb &&
556-
git init initial-branch-config &&
556+
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= git init initial-branch-config &&
557557
git -C initial-branch-config symbolic-ref HEAD >actual &&
558558
grep nmb actual
559559
'
560560

561+
test_expect_success 'overridden default main branch name (env)' '
562+
test_config_global init.defaultBranch nmb &&
563+
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=env git init main-branch-env &&
564+
git -C main-branch-env symbolic-ref HEAD >actual &&
565+
grep env actual
566+
'
567+
561568
test_expect_success 'invalid default branch name' '
562-
test_config_global init.defaultBranch "with space" &&
563-
test_must_fail git init initial-branch-invalid 2>err &&
569+
test_must_fail env GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME="with space" \
570+
git init initial-branch-invalid 2>err &&
564571
test_i18ngrep "invalid branch name" err
565572
'
566573

t/t5606-clone-options.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ test_expect_success 'redirected clone -v does show progress' '
3737

3838
test_expect_success 'chooses correct default initial branch name' '
3939
git init --bare empty &&
40+
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
4041
git -c init.defaultBranch=up clone empty whats-up &&
4142
test refs/heads/up = $(git -C whats-up symbolic-ref HEAD) &&
4243
test refs/heads/up = $(git -C whats-up config branch.up.merge)
@@ -51,9 +52,11 @@ test_expect_success 'guesses initial branch name correctly' '
5152
5253
git -c init.defaultBranch=none init --bare no-head &&
5354
git -C initial-branch push ../no-head guess abc &&
55+
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
5456
git clone no-head is-it2 &&
5557
test_must_fail git -C is-it2 symbolic-ref refs/remotes/origin/HEAD &&
5658
git -C no-head update-ref --no-deref HEAD refs/heads/guess &&
59+
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
5760
git -c init.defaultBranch=guess clone no-head is-it3 &&
5861
test refs/remotes/origin/guess = \
5962
$(git -C is-it3 symbolic-ref refs/remotes/origin/HEAD)

t/test-lib.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,3 +1702,10 @@ test_lazy_prereq SHA1 '
17021702
test_lazy_prereq REBASE_P '
17031703
test -z "$GIT_TEST_SKIP_REBASE_P"
17041704
'
1705+
# Special-purpose prereq for transitioning to a new default branch name:
1706+
# Some tests need more than just a mindless (case-preserving) s/master/main/g
1707+
# replacement. The non-trivial adjustments are guarded behind this
1708+
# prerequisite, acting kind of as a feature flag
1709+
test_lazy_prereq PREPARE_FOR_MAIN_BRANCH '
1710+
test "$GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME" = main
1711+
'

0 commit comments

Comments
 (0)