summaryrefslogtreecommitdiffstats
path: root/tests/test_project.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_project.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_project.py')
-rw-r--r--tests/test_project.py15
1 files changed, 14 insertions, 1 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)