|
50 | 50 | 'remote': {'id': 'repo2'},
|
51 | 51 | },
|
52 | 52 | },
|
53 |
| - 'default-branch-scheme': 'master', |
| 53 | + 'default-branch-scheme': 'main', |
54 | 54 | 'branch-schemes': {
|
55 |
| - 'master': { |
56 |
| - 'aliases': ['master'], |
| 55 | + 'main': { |
| 56 | + 'aliases': ['main'], |
57 | 57 | 'repos': {
|
58 |
| - 'repo1': 'master', |
59 |
| - 'repo2': 'master', |
| 58 | + 'repo1': 'main', |
| 59 | + 'repo2': 'main', |
60 | 60 | }
|
61 | 61 | }
|
62 | 62 | }
|
63 | 63 | }
|
64 | 64 |
|
65 | 65 |
|
| 66 | +class CallQuietlyException(Exception): |
| 67 | + def __init__(self, command, returncode, output): |
| 68 | + self.command = command |
| 69 | + self.returncode = returncode |
| 70 | + self.output = output |
| 71 | + |
| 72 | + def __str__(self): |
| 73 | + return f"Command returned a non-zero exit status {self.returncode}:\n"\ |
| 74 | + f"Command: {' '.join(self.command)}\n" \ |
| 75 | + f"Output: {self.output.decode('utf-8')}" |
| 76 | + |
| 77 | + |
66 | 78 | def call_quietly(*args, **kwargs):
|
67 |
| - with open(os.devnull, 'w') as f: |
68 |
| - kwargs['stdout'] = f |
69 |
| - kwargs['stderr'] = f |
70 |
| - subprocess.check_call(*args, **kwargs) |
| 79 | + kwargs['stderr'] = subprocess.STDOUT |
| 80 | + try: |
| 81 | + subprocess.check_output(*args, **kwargs) |
| 82 | + except subprocess.CalledProcessError as e: |
| 83 | + raise CallQuietlyException(command=e.cmd, returncode=e.returncode, |
| 84 | + output=e.stdout) from e |
71 | 85 |
|
72 | 86 |
|
73 | 87 | def create_dir(d):
|
@@ -101,15 +115,19 @@ def setup_mock_remote(base_dir):
|
101 | 115 | create_dir(remote_repo_path)
|
102 | 116 | create_dir(local_repo_path)
|
103 | 117 | call_quietly(['git', 'init', '--bare', remote_repo_path])
|
| 118 | + call_quietly(['git', 'symbolic-ref', 'HEAD', 'refs/heads/main'], |
| 119 | + cwd=remote_repo_path) |
104 | 120 | call_quietly(['git', 'clone', '-l', remote_repo_path, local_repo_path])
|
| 121 | + call_quietly(['git', 'symbolic-ref', 'HEAD', 'refs/heads/main'], |
| 122 | + cwd=local_repo_path) |
105 | 123 | for (i, (filename, contents)) in enumerate(v):
|
106 | 124 | filename_path = os.path.join(local_repo_path, filename)
|
107 | 125 | with open(filename_path, 'w') as f:
|
108 | 126 | f.write(contents)
|
109 | 127 | call_quietly(['git', 'add', filename], cwd=local_repo_path)
|
110 | 128 | call_quietly(['git', 'commit', '-m', 'Commit %d' % i],
|
111 | 129 | cwd=local_repo_path)
|
112 |
| - call_quietly(['git', 'push', 'origin', 'master'], |
| 130 | + call_quietly(['git', 'push', 'origin', 'main'], |
113 | 131 | cwd=local_repo_path)
|
114 | 132 |
|
115 | 133 | base_config = MOCK_CONFIG
|
|
0 commit comments