Skip to content

Commit eb77eaa

Browse files
authored
Merge pull request #40129 from jorng/fix_update_checkout_tests
update_checkout (tests): Use 'main' for test branch
2 parents 476f069 + 1b344b3 commit eb77eaa

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

utils/update_checkout/tests/scheme_mock.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,38 @@
5050
'remote': {'id': 'repo2'},
5151
},
5252
},
53-
'default-branch-scheme': 'master',
53+
'default-branch-scheme': 'main',
5454
'branch-schemes': {
55-
'master': {
56-
'aliases': ['master'],
55+
'main': {
56+
'aliases': ['main'],
5757
'repos': {
58-
'repo1': 'master',
59-
'repo2': 'master',
58+
'repo1': 'main',
59+
'repo2': 'main',
6060
}
6161
}
6262
}
6363
}
6464

6565

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+
6678
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
7185

7286

7387
def create_dir(d):
@@ -101,15 +115,19 @@ def setup_mock_remote(base_dir):
101115
create_dir(remote_repo_path)
102116
create_dir(local_repo_path)
103117
call_quietly(['git', 'init', '--bare', remote_repo_path])
118+
call_quietly(['git', 'symbolic-ref', 'HEAD', 'refs/heads/main'],
119+
cwd=remote_repo_path)
104120
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)
105123
for (i, (filename, contents)) in enumerate(v):
106124
filename_path = os.path.join(local_repo_path, filename)
107125
with open(filename_path, 'w') as f:
108126
f.write(contents)
109127
call_quietly(['git', 'add', filename], cwd=local_repo_path)
110128
call_quietly(['git', 'commit', '-m', 'Commit %d' % i],
111129
cwd=local_repo_path)
112-
call_quietly(['git', 'push', 'origin', 'master'],
130+
call_quietly(['git', 'push', 'origin', 'main'],
113131
cwd=local_repo_path)
114132

115133
base_config = MOCK_CONFIG

utils/update_checkout/tests/test_update_worktree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_worktree(self):
5353
self.call([self.update_checkout_path,
5454
'--config', self.config_path,
5555
'--source-root', self.worktree_path,
56-
'--scheme', 'master'])
56+
'--scheme', 'main'])
5757

5858
def setUp(self):
5959
super(WorktreeTestCase, self).setUp()

0 commit comments

Comments
 (0)