summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/test_project.py15
-rw-r--r--tests/test_wrapper.py15
2 files changed, 28 insertions, 2 deletions
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
26import unittest 26import unittest
27 27
28import error 28import error
29import git_command
29import git_config 30import git_config
30import platform_utils 31import platform_utils
31import project 32import project
@@ -38,7 +39,19 @@ def TempGitTree():
38 # Python 2 support entirely. 39 # Python 2 support entirely.
39 try: 40 try:
40 tempdir = tempfile.mkdtemp(prefix='repo-tests') 41 tempdir = tempfile.mkdtemp(prefix='repo-tests')
41 subprocess.check_call(['git', 'init'], cwd=tempdir) 42
43 # Tests need to assume, that main is default branch at init,
44 # which is not supported in config until 2.28.
45 cmd = ['git', 'init']
46 if git_command.git_require((2, 28, 0)):
47 cmd += ['--initial-branch=main']
48 else:
49 # Use template dir for init.
50 templatedir = tempfile.mkdtemp(prefix='.test-template')
51 with open(os.path.join(templatedir, 'HEAD'), 'w') as fp:
52 fp.write('ref: refs/heads/main\n')
53 cmd += ['--template=', templatedir]
54 subprocess.check_call(cmd, cwd=tempdir)
42 yield tempdir 55 yield tempdir
43 finally: 56 finally:
44 platform_utils.rmtree(tempdir) 57 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
25import tempfile 25import tempfile
26import unittest 26import unittest
27 27
28import git_command
28import platform_utils 29import platform_utils
29from pyversion import is_python3 30from pyversion import is_python3
30import wrapper 31import wrapper
@@ -357,7 +358,19 @@ class GitCheckoutTestCase(RepoWrapperTestCase):
357 358
358 remote = os.path.join(cls.GIT_DIR, 'remote') 359 remote = os.path.join(cls.GIT_DIR, 'remote')
359 os.mkdir(remote) 360 os.mkdir(remote)
360 run_git('init', cwd=remote) 361
362 # Tests need to assume, that main is default branch at init,
363 # which is not supported in config until 2.28.
364 if git_command.git_require((2, 28, 0)):
365 initstr = '--initial-branch=main'
366 else:
367 # Use template dir for init.
368 templatedir = tempfile.mkdtemp(prefix='.test-template')
369 with open(os.path.join(templatedir, 'HEAD'), 'w') as fp:
370 fp.write('ref: refs/heads/main\n')
371 initstr = '--template=' + templatedir
372
373 run_git('init', initstr, cwd=remote)
361 run_git('commit', '--allow-empty', '-minit', cwd=remote) 374 run_git('commit', '--allow-empty', '-minit', cwd=remote)
362 run_git('branch', 'stable', cwd=remote) 375 run_git('branch', 'stable', cwd=remote)
363 run_git('tag', 'v1.0', cwd=remote) 376 run_git('tag', 'v1.0', cwd=remote)