All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Johannes Schindelin <johannes.schindelin@gmx.de>,
	Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: [PATCH 03/10] tests: start moving to a different default main branch name
Date: Mon, 19 Oct 2020 19:31:34 +0000	[thread overview]
Message-ID: <d9469202c2dda238882150452fac1aa7fc7fbfec.1603135902.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.758.git.1603135902.gitgitgadget@gmail.com>

From: Johannes Schindelin <johannes.schindelin@gmx.de>

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>
---
 refs.c                    |  5 ++++-
 t/lib-submodule-update.sh |  2 +-
 t/t0001-init.sh           | 13 ++++++++++---
 t/t5606-clone-options.sh  |  3 +++
 t/test-lib.sh             |  7 +++++++
 5 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/refs.c b/refs.c
index fa01153151..392f0bbf68 100644
--- a/refs.c
+++ b/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)
diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
index 87a759149f..bd3fa3c6da 100644
--- a/t/lib-submodule-update.sh
+++ b/t/lib-submodule-update.sh
@@ -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}"
 	)
 }
 
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 2f7c3dcd0f..69a320489f 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -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
 '
 
diff --git a/t/t5606-clone-options.sh b/t/t5606-clone-options.sh
index e69427f881..856eebf222 100755
--- a/t/t5606-clone-options.sh
+++ b/t/t5606-clone-options.sh
@@ -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)
diff --git a/t/test-lib.sh b/t/test-lib.sh
index ef31f40037..6b35070d22 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -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
+'
-- 
gitgitgadget


  parent reply	other threads:[~2020-10-19 19:31 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-19 19:31 [PATCH 00/10] Prepare for changing the default branch name main (last manual part) Johannes Schindelin via GitGitGadget
2020-10-19 19:31 ` [PATCH 01/10] fmt-merge-msg: also suppress "into main" by default Johannes Schindelin via GitGitGadget
2020-10-21 22:12   ` Junio C Hamano
2020-10-22 12:28     ` Johannes Schindelin
2020-10-19 19:31 ` [PATCH 02/10] t9801: use `--` in preparation for default branch rename Johannes Schindelin via GitGitGadget
2020-10-21 22:19   ` Junio C Hamano
2020-10-19 19:31 ` Johannes Schindelin via GitGitGadget [this message]
2020-10-21 22:22   ` [PATCH 03/10] tests: start moving to a different default main branch name Junio C Hamano
2020-10-19 19:31 ` [PATCH 04/10] t4013: prepare for the new default branch name "main" Johannes Schindelin via GitGitGadget
2020-10-21 22:23   ` Junio C Hamano
2020-10-22 12:27     ` Johannes Schindelin
2020-10-19 19:31 ` [PATCH 05/10] t6200: adjust suppression pattern to also match "main" Johannes Schindelin via GitGitGadget
2020-10-21 22:27   ` Junio C Hamano
2020-10-22 13:01     ` Johannes Schindelin
2020-10-19 19:31 ` [PATCH 06/10] t5703: adjust a test case for the upcoming default branch name Johannes Schindelin via GitGitGadget
2020-10-21 22:34   ` Junio C Hamano
2020-10-19 19:31 ` [PATCH 07/10] t3200: prepare for `main` being shorter than `master` Johannes Schindelin via GitGitGadget
2020-10-21 22:39   ` Junio C Hamano
2020-10-22 13:08     ` Johannes Schindelin
2020-10-19 19:31 ` [PATCH 08/10] t9902: prepare a test for the upcoming default branch name Johannes Schindelin via GitGitGadget
2020-10-19 19:31 ` [PATCH 09/10] tests: prepare aligned mentions of the " Johannes Schindelin via GitGitGadget
2020-10-19 19:31 ` [PATCH 10/10] t1400: prepare for `main` being " Johannes Schindelin via GitGitGadget
2020-10-21 21:59 ` [PATCH 00/10] Prepare for changing the default branch name main (last manual part) Junio C Hamano
2020-10-22 13:11   ` Johannes Schindelin
2020-10-23 13:59 ` [PATCH v2 0/9] " Johannes Schindelin via GitGitGadget
2020-10-23 13:59   ` [PATCH v2 1/9] fmt-merge-msg: also suppress "into main" by default Johannes Schindelin via GitGitGadget
2020-10-23 13:59   ` [PATCH v2 2/9] t9801: use `--` in preparation for default branch rename Johannes Schindelin via GitGitGadget
2020-10-23 14:00   ` [PATCH v2 3/9] tests: start moving to a different default main branch name Johannes Schindelin via GitGitGadget
2020-10-23 14:00   ` [PATCH v2 4/9] t6200: adjust suppression pattern to also match "main" Johannes Schindelin via GitGitGadget
2020-10-23 14:00   ` [PATCH v2 5/9] t5703: adjust a test case for the upcoming default branch name Johannes Schindelin via GitGitGadget
2020-10-23 14:00   ` [PATCH v2 6/9] t3200: prepare for `main` being shorter than `master` Johannes Schindelin via GitGitGadget
2020-10-23 14:00   ` [PATCH v2 7/9] t9902: prepare a test for the upcoming default branch name Johannes Schindelin via GitGitGadget
2020-10-23 14:00   ` [PATCH v2 8/9] tests: prepare aligned mentions of the " Johannes Schindelin via GitGitGadget
2020-10-23 14:00   ` [PATCH v2 9/9] t1400: prepare for `main` being " Johannes Schindelin via GitGitGadget
2020-10-23 15:59   ` [PATCH v2 0/9] Prepare for changing the default branch name main (last manual part) Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d9469202c2dda238882150452fac1aa7fc7fbfec.1603135902.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=johannes.schindelin@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.