diff --git a/tests/test_project.py b/tests/test_project.py index 924a2459..02285e2f 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -26,6 +26,7 @@ import tempfile import unittest import error +import git_command import git_config import platform_utils import project @@ -38,7 +39,19 @@ def TempGitTree(): # Python 2 support entirely. try: tempdir = tempfile.mkdtemp(prefix='repo-tests') - subprocess.check_call(['git', 'init'], cwd=tempdir) + + # Tests need to assume, that main is default branch at init, + # which is not supported in config until 2.28. + cmd = ['git', 'init'] + if git_command.git_require((2, 28, 0)): + cmd += ['--initial-branch=main'] + else: + # Use template dir for init. + templatedir = tempfile.mkdtemp(prefix='.test-template') + with open(os.path.join(templatedir, 'HEAD'), 'w') as fp: + fp.write('ref: refs/heads/main\n') + cmd += ['--template=', templatedir] + subprocess.check_call(cmd, cwd=tempdir) yield tempdir finally: platform_utils.rmtree(tempdir) diff --git a/tests/test_wrapper.py b/tests/test_wrapper.py index d22dc4ee..069a5c3b 100644 --- a/tests/test_wrapper.py +++ b/tests/test_wrapper.py @@ -25,6 +25,7 @@ import shutil import tempfile import unittest +import git_command import platform_utils from pyversion import is_python3 import wrapper @@ -357,7 +358,19 @@ class GitCheckoutTestCase(RepoWrapperTestCase): remote = os.path.join(cls.GIT_DIR, 'remote') os.mkdir(remote) - run_git('init', cwd=remote) + + # Tests need to assume, that main is default branch at init, + # which is not supported in config until 2.28. + if git_command.git_require((2, 28, 0)): + initstr = '--initial-branch=main' + else: + # Use template dir for init. + templatedir = tempfile.mkdtemp(prefix='.test-template') + with open(os.path.join(templatedir, 'HEAD'), 'w') as fp: + fp.write('ref: refs/heads/main\n') + initstr = '--template=' + templatedir + + run_git('init', initstr, cwd=remote) run_git('commit', '--allow-empty', '-minit', cwd=remote) run_git('branch', 'stable', cwd=remote) run_git('tag', 'v1.0', cwd=remote)