Skip to content

Commit

Permalink
Merge branch 'mr/ramonat/default-git-branch' into 'master'
Browse files Browse the repository at this point in the history
Change the default git branch name when running tests

See merge request it/e3-core!16
  • Loading branch information
enzbang committed Jul 19, 2024
2 parents d62ca5c + ea6364a commit 502cad9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/e3/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion tests/tests_e3/anod/checkout_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 502cad9

Please sign in to comment.