Skip to content

Commit 47c7b65

Browse files
committed
fetch: select a valid branch to workaround a gix bug
1 parent d83c9a7 commit 47c7b65

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

acbs/fetch.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,29 @@ def gix_fetch(info: ACBSSourceInfo, source_location: str, name: str) -> Optional
143143
else:
144144
logging.info('Updating repository with gix...')
145145
# gix doesn't have the --prune option yet.
146-
# FIXME: reset HEAD to master to fix gix can't second fetch src issue.
147-
subprocess.check_call(['git', 'symbolic-ref', 'HEAD'], cwd=full_path)
146+
# FIXME: reset HEAD to the first valid branch to fix gix can't second fetch src issue.
147+
subprocess.check_call(
148+
['git', 'symbolic-ref', 'HEAD', 'refs/heads/HEAD'], cwd=full_path)
149+
valid_branches: list(str) = subprocess.check_output(
150+
['git', 'branch'], cwd=full_path, encoding='utf-8').splitlines()
151+
for word in valid_branches:
152+
word = word.strip()
153+
if len(word) > 0:
154+
valid_branches: str = word
155+
break
156+
if isinstance(valid_branches, list):
157+
logging.warn(
158+
'No valid branches found. Falling back to traditional git.')
159+
raise ValueError('No valid branches found')
160+
subprocess.check_call(
161+
['git', 'symbolic-ref', 'HEAD', 'refs/heads/' + valid_branches], cwd=full_path)
148162
os.remove(os.path.join(full_path, "index"))
149163
subprocess.check_call(
150164
['gix', 'fetch', 'origin', '+refs/heads/*:refs/heads/*'], cwd=full_path)
151165
info.source_location = full_path
152166
return info
153167

168+
154169
def git_processor(package: ACBSPackageInfo, index: int, source_name: str) -> None:
155170
info = package.source_uri[index]
156171
if not info.revision:

0 commit comments

Comments
 (0)