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 <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Johannes Schindelin 2020-10-23 14:00:00 +00:00 коммит произвёл Junio C Hamano
Родитель 25ad0dc130
Коммит 704fed9ea2
5 изменённых файлов: 25 добавлений и 5 удалений

5
refs.c
Просмотреть файл

@ -567,8 +567,11 @@ char *repo_default_branch_name(struct repository *r)
const char *config_key = "init.defaultbranch";
const char *config_display_key = "init.defaultBranch";
char *ret = NULL, *full_ref;
const char *env = getenv("GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME");
if (repo_config_get_string(r, config_key, &ret) < 0)
if (env && *env)
ret = xstrdup(env);
else if (repo_config_get_string(r, config_key, &ret) < 0)
die(_("could not retrieve `%s`"), config_display_key);
if (!ret)

Просмотреть файл

@ -144,7 +144,7 @@ create_lib_submodule_repo () {
git checkout -b valid_sub1 &&
git revert HEAD &&
git checkout master
git checkout "${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}"
)
}

Просмотреть файл

@ -553,14 +553,21 @@ test_expect_success '--initial-branch' '
test_expect_success 'overridden default initial branch name (config)' '
test_config_global init.defaultBranch nmb &&
git init initial-branch-config &&
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= git init initial-branch-config &&
git -C initial-branch-config symbolic-ref HEAD >actual &&
grep nmb actual
'
test_expect_success 'overridden default main branch name (env)' '
test_config_global init.defaultBranch nmb &&
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=env git init main-branch-env &&
git -C main-branch-env symbolic-ref HEAD >actual &&
grep env actual
'
test_expect_success 'invalid default branch name' '
test_config_global init.defaultBranch "with space" &&
test_must_fail git init initial-branch-invalid 2>err &&
test_must_fail env GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME="with space" \
git init initial-branch-invalid 2>err &&
test_i18ngrep "invalid branch name" err
'

Просмотреть файл

@ -37,6 +37,7 @@ test_expect_success 'redirected clone -v does show progress' '
test_expect_success 'chooses correct default initial branch name' '
git init --bare empty &&
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
git -c init.defaultBranch=up clone empty whats-up &&
test refs/heads/up = $(git -C whats-up symbolic-ref HEAD) &&
test refs/heads/up = $(git -C whats-up config branch.up.merge)
@ -51,9 +52,11 @@ test_expect_success 'guesses initial branch name correctly' '
git -c init.defaultBranch=none init --bare no-head &&
git -C initial-branch push ../no-head guess abc &&
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
git clone no-head is-it2 &&
test_must_fail git -C is-it2 symbolic-ref refs/remotes/origin/HEAD &&
git -C no-head update-ref --no-deref HEAD refs/heads/guess &&
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
git -c init.defaultBranch=guess clone no-head is-it3 &&
test refs/remotes/origin/guess = \
$(git -C is-it3 symbolic-ref refs/remotes/origin/HEAD)

Просмотреть файл

@ -1702,3 +1702,10 @@ test_lazy_prereq SHA1 '
test_lazy_prereq REBASE_P '
test -z "$GIT_TEST_SKIP_REBASE_P"
'
# Special-purpose prereq for transitioning to a new default branch name:
# Some tests need more than just a mindless (case-preserving) s/master/main/g
# replacement. The non-trivial adjustments are guarded behind this
# prerequisite, acting kind of as a feature flag
test_lazy_prereq PREPARE_FOR_MAIN_BRANCH '
test "$GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME" = main
'