Skip to content

Commit d3048f5

Browse files
auto-cache: use default remote branch
When a project within auto-cache is updated, make sure that the HEAD points to default remote branch to avoid issues during cloning, e.g. "warning: remote HEAD refers to nonexistent ref, unable to checkout"
1 parent ff759fb commit d3048f5

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/west/app/project.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,28 @@ def handle_auto_cache(self, project):
17801780
return
17811781

17821782
# The auto-cache needs to be updated. Sync with remote.
1783+
# Note: always make sure that the auto-cache HEAD points to correct
1784+
# remote HEAD, to avoid issues while updating the cache or cloning
1785+
# from auto-cache, e.g. if the remote default branch has changed:
1786+
# warning: remote HEAD refers to nonexistent ref, unable to checkout
17831787
self.dbg(f'{project.name}: update auto-cache ({cache_dir}) with remote')
1788+
cp = project.git(
1789+
['ls-remote', '--symref', 'HEAD'],
1790+
cwd=cache_dir,
1791+
capture_stdout=True,
1792+
capture_stderr=True,
1793+
check=False,
1794+
)
1795+
if cp.returncode == 0:
1796+
# extract branch name from stdout, e.g. "ref: refs/heads/main HEAD"
1797+
remote_head = cp.stdout.decode('utf-8').split()[1]
1798+
print(f"xxx: {remote_head}")
1799+
project.git(
1800+
['symbolic-ref', 'HEAD', remote_head],
1801+
cwd=cache_dir,
1802+
capture_stdout=True,
1803+
check=False,
1804+
)
17841805
project.git(['remote', 'update', '--prune'], cwd=cache_dir, check=False)
17851806

17861807
def init_project(self, project):

0 commit comments

Comments
 (0)