From 5e1130b682a70b4eaf98d1a1cab371b4bdad76c6 Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Jul 09 2021 08:47:28 +0000 Subject: Tests: Fix setting branch name with old git In older versions of git, like those available in EL8, `git init` doesn't accept the -b/--initial-branch parameter. Instead, set the branch name afterwards. Signed-off-by: Nils Philippsen --- diff --git a/tests/commands/__init__.py b/tests/commands/__init__.py index ae26ee0..702589e 100644 --- a/tests/commands/__init__.py +++ b/tests/commands/__init__.py @@ -58,7 +58,9 @@ class CommandTestCase(unittest.TestCase): # Create a bare Git repository moduledir = os.path.join(self.gitroot, module) os.makedirs(moduledir) - subprocess.check_call(['git', 'init', '--bare', '-b', 'master'], cwd=moduledir, + subprocess.check_call(['git', 'init', '--bare'], cwd=moduledir, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + subprocess.check_call(['git', 'symbolic-ref', 'HEAD', 'refs/heads/master'], cwd=moduledir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # Clone it, and do the minimal Dist Git setup @@ -82,6 +84,8 @@ class CommandTestCase(unittest.TestCase): subprocess.check_call(['git', 'commit', '-m', 'Initial setup of the repo'], cwd=clonedir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + subprocess.check_call(['git', 'branch', '-m', 'master'], cwd=clonedir, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) subprocess.check_call(['git', 'push', 'origin', 'master'], cwd=clonedir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) diff --git a/tests/test_cli.py b/tests/test_cli.py index a40e26c..5273e1a 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1444,7 +1444,8 @@ class TestImportSrpm(LookasideCacheMock, CliTestCase): self.chaos_repo = tempfile.mkdtemp(prefix='rpkg-tests-chaos-repo-') cmds = ( - ['git', 'init', '-b', 'master'], + ['git', 'init'], + ['git', 'checkout', '-b', 'master'], ['touch', 'README.md'], ['git', 'add', 'README.md'], ['git', 'config', 'user.name', 'tester'], diff --git a/tests/test_retire.py b/tests/test_retire.py index 3f68a2a..5868cfe 100644 --- a/tests/test_retire.py +++ b/tests/test_retire.py @@ -32,7 +32,8 @@ class RetireTestCase(unittest.TestCase): def _setup_repo(self, origin): cmds = ( - ['git', 'init', '-b', 'master'], + ['git', 'init'], + ['git', 'checkout', '-b', 'master'], ['git', 'config', 'user.name', 'John Doe'], ['git', 'config', 'user.email', 'jdoe@example.com'], ['git', 'remote', 'add', 'origin', origin], diff --git a/tests/utils.py b/tests/utils.py index 088f79a..c686040 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -157,7 +157,8 @@ class RepoCreationMixin(object): f.write(spec_file) git_cmds = [ - ['git', 'init', '-b', 'master'], + ['git', 'init'], + ['git', 'checkout', '-b', 'master'], ['touch', 'sources', 'CHANGELOG.rst'], ['git', 'add', spec_file_path, 'sources', 'CHANGELOG.rst'], ['git', 'config', 'user.email', 'tester@example.com'],