Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix git submodule tests using file: protocol #159

Merged
merged 6 commits into from Oct 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 24 additions & 6 deletions tests.py
Expand Up @@ -2,6 +2,7 @@
import locale
import os
import posixpath
import re
import shutil
import subprocess
import sys
Expand Down Expand Up @@ -928,12 +929,25 @@ class VCSHelper:

# override in subclasses
command = None # type: Optional[str]
extra_env = {}

@property
def version(self):
if not hasattr(self, '_version'):
if not self.is_installed():
self._version = None
return self._version

@property
def version_tuple(self):
return tuple(map(int, re.findall(r'\d+', self.version)))

def is_installed(self):
try:
p = subprocess.Popen([self.command, '--version'],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout, stderr = p.communicate()
self._version = stdout.decode('ascii', 'backslashreplace').strip()
rc = p.wait()
return (rc == 0)
except OSError:
Expand All @@ -946,14 +960,12 @@ def _run(self, *command):
command = [s.encode(locale.getpreferredencoding()) for s in command]
print('$', ' '.join(command))
p = subprocess.Popen(command, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
stderr=subprocess.STDOUT,
env={**os.environ, **self.extra_env})
stdout, stderr = p.communicate()
rc = p.wait()
if stdout:
print(
stdout if isinstance(stdout, str) else
stdout.decode('ascii', 'backslashreplace')
)
print(stdout.decode('ascii', 'backslashreplace'))
if rc:
raise subprocess.CalledProcessError(rc, command[0], output=stdout)

Expand Down Expand Up @@ -1051,9 +1063,15 @@ def test_get_vcs_files_empty(self):
class GitHelper(VCSHelper):

command = 'git'
extra_env = dict(
GIT_ALLOW_PROTOCOL='file',
)

def _init_vcs(self):
self._run('git', 'init')
if self.version_tuple >= (2, 28):
self._run('git', 'init', '-b', 'main')
else:
self._run('git', 'init')
self._run('git', 'config', 'user.name', 'Unit Test')
self._run('git', 'config', 'user.email', 'test@example.com')

Expand Down