Skip to content

Commit 154bc4e

Browse files
committed
contest: don't create local branches
Move to a git commit from remove but don't create a local branch. Looks like nothing actually requires it. Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 9ba29bb commit 154bc4e

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

contest/remote/gh.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ def test_run(binfo, rinfo, cbarg, config, start):
151151
base = config.get('gh', 'base')
152152

153153
subprocess.run('git checkout ' + base, cwd=tree_path, shell=True, check=True)
154-
res = subprocess.run('git merge ' + binfo['branch'], cwd=tree_path, shell=True)
154+
res = subprocess.run('git merge ' + rinfo['branch-ref'],
155+
cwd=tree_path, shell=True)
155156
if res.returncode != 0:
156157
# If rerere fixed it, just commit
157158
res = subprocess.run('git diff -s --exit-code', cwd=tree_path, shell=True)

contest/remote/lib/fetcher.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,15 @@ def _write_result(self, data, run_cookie):
8585

8686
return self._url_path + '/' + file_name
8787

88-
def _run_test(self, binfo):
88+
def _run_test(self, binfo, ref):
8989
self._result_set(binfo['branch'], None)
9090

9191
start = datetime.datetime.now(datetime.UTC)
9292
run_id_cookie = str(int(start.timestamp() / 60) % 1000000)
93-
rinfo = {'run-cookie': run_id_cookie}
93+
rinfo = {
94+
'run-cookie': run_id_cookie,
95+
'branch-ref': ref,
96+
}
9497
results = self._cb(binfo, rinfo, self._cbarg)
9598
end = datetime.datetime.now(datetime.UTC)
9699

@@ -109,19 +112,23 @@ def _run_test(self, binfo):
109112

110113
self._result_set(binfo['branch'], url)
111114

112-
def _clean_old_branches(self, remote, current):
113-
ret = subprocess.run('git branch',
114-
cwd=self._tree_path, shell=True,
115-
capture_output=True, check=True)
115+
def _find_branch(self, name):
116+
ret = subprocess.run(['git', 'describe', 'main'],
117+
check=False, capture_output=True)
118+
if ret.returncode == 0:
119+
# git found a direct hit for the name, use as is
120+
return name
116121

117-
existing = set([x.strip() for x in ret.stdout.decode('utf-8').split('\n')])
122+
# Try to find the branch in one of the remotes (will return remote/name)
123+
ret = subprocess.run(['git', 'branch', '-r', '-l', '*/' + name],
124+
cwd=self._tree_path,
125+
capture_output=True, check=True)
118126

119-
for b in remote:
120-
if b["branch"] in existing and b["branch"] != current:
121-
print("Clean up old branch", b["branch"])
122-
subprocess.run('git branch -D ' + b["branch"],
123-
cwd=self._tree_path, shell=True,
124-
check=True)
127+
branches = ret.stdout.decode('utf-8').strip()
128+
branches = [x.strip() for x in branches.split('\n')]
129+
if len(branches) != 1:
130+
print("Unexpected number of branches found:", branches)
131+
return branches[0]
125132

126133
def _run_once(self):
127134
r = requests.get(self._branches_url)
@@ -160,7 +167,8 @@ def _run_once(self):
160167
print("HEAD is still locked! Sleeping..")
161168
time.sleep(0.2)
162169

163-
subprocess.run('git checkout ' + to_test["branch"],
170+
ref = self._find_branch(to_test["branch"])
171+
subprocess.run('git checkout --detach ' + ref,
164172
cwd=self._tree_path, shell=True, check=True)
165173

166174
if self._patches_path is not None:
@@ -169,8 +177,7 @@ def _run_once(self):
169177
subprocess.run('git apply -v {}'.format(realpath),
170178
cwd=self._tree_path, shell=True)
171179

172-
self._clean_old_branches(branches, to_test["branch"])
173-
self._run_test(to_test)
180+
self._run_test(to_test, ref)
174181

175182
def run(self):
176183
while self.life.next_poll():

0 commit comments

Comments
 (0)