summaryrefslogtreecommitdiffstats
path: root/tests/test_wrapper.py
diff options
context:
space:
mode:
authorFredrik de Groot <fredrik.de.groot@volvocars.com>2020-12-01 15:58:53 +0100
committerFredrik de Groot <fredrik.de.groot@volvocars.com>2020-12-03 07:29:59 +0000
commit6342d5691478873708ee9363bd7dc8e275a75098 (patch)
treeb24c54d1dd6bcb6858baf17cca9fbd2d40d720ae /tests/test_wrapper.py
parent9dfd69f7730bc73d3a1e3a97e99041dcf28f3d1f (diff)
downloadgit-repo-6342d5691478873708ee9363bd7dc8e275a75098.tar.gz
Fix tests after "use new main branch"
Tests worked fine if init.defaultBranch main was used, but failed due to git branch reasons if master was still used. Since we can only use init.defaultBranch if git version >= 2.28, I also went with a template dir HEAD main tweak if lower so tests now pass regardless of client git default branch and version. Test: Ran tests with ~/.gitconfig:init.defaultBranch=master Test: Ran tests with ~/.gitconfig:init.defaultBranch=main Test: Ran tests for both code branches of git require Change-Id: I49fa1e4ae45b8aec16a093132ee9fa466cbc11ec Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/290404 Tested-by: Fredrik de Groot <fredrik.de.groot@volvocars.com> Reviewed-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'tests/test_wrapper.py')
-rw-r--r--tests/test_wrapper.py15
1 files changed, 14 insertions, 1 deletions
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)