From 8e544c5ed3e91070e8de5d3b9afb405bdbc22098 Mon Sep 17 00:00:00 2001 From: Olivier Ramonat Date: Fri, 19 Jul 2024 12:04:51 +0200 Subject: [PATCH 1/2] Do not assume that the default git branch is master --- tests/tests_e3/anod/checkout_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/tests_e3/anod/checkout_test.py b/tests/tests_e3/anod/checkout_test.py index 790570dd..d8a5e771 100644 --- a/tests/tests_e3/anod/checkout_test.py +++ b/tests/tests_e3/anod/checkout_test.py @@ -239,7 +239,8 @@ def test_max_depth_checkout(self): r.git_cmd(["add", "file5.txt"]) r.git_cmd(["commit", "-m", "third commit"]) - result = m.update(vcs="git", url=url, revision="master") + main_branch = r.git_cmd(["branch", "--show-current"]).out + result = m.update(vcs="git", url=url, revision=main_branch) myrepo = GitRepository(os.path.abspath("myrepo")) myrepo.git_cmd(["log", "--pretty=format:%s"], output="log.txt") From ea6364a378c98cc25a3fc78a0f4eacb9916e3abd Mon Sep 17 00:00:00 2001 From: Olivier Ramonat Date: Fri, 19 Jul 2024 12:05:06 +0200 Subject: [PATCH 2/2] Change the default git branch name when running tests We often assume that the default git branch is named "master" when writing tests. It is better to either explicitely set the branch name or to extract it with `git branch --show-current` --- src/e3/pytest.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/e3/pytest.py b/src/e3/pytest.py index 6c1a8244..cc125fd7 100644 --- a/src/e3/pytest.py +++ b/src/e3/pytest.py @@ -96,6 +96,15 @@ def env_protect(request: pytest.FixtureRequest) -> None: if "E3_HOSTNAME" in os.environ: del os.environ["E3_HOSTNAME"] + # Set environment variables for the default Git branch to + # ensure that we do not assume that the default branch is + # named master. The best practice when writing test is + # to either explicitely name the branch or to get the + # value with `git branch --show-current` + os.environ["GIT_CONFIG_COUNT"] = "1" + os.environ["GIT_CONFIG_KEY_0"] = "init.defaultbranch" + os.environ["GIT_CONFIG_VALUE_0"] = "default_branch" + def restore_env() -> None: Env().restore() rm(tempd, True)