Skip to content

Commit 6551422

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 6551422

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/west/app/project.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,26 @@ 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:
17831786
self.dbg(f'{project.name}: update auto-cache ({cache_dir}) with remote')
1787+
cp = project.git(
1788+
['ls-remote', '--symref', 'HEAD'],
1789+
cwd=cache_dir,
1790+
capture_stdout=True,
1791+
capture_stderr=True,
1792+
check=False,
1793+
)
1794+
if cp.returncode == 0:
1795+
# extract branch name from stdout, e.g. "ref: refs/heads/main HEAD"
1796+
remote_head = cp.stdout.decode('utf-8').split()[1]
1797+
project.git(
1798+
['symbolic-ref', 'HEAD', remote_head],
1799+
cwd=cache_dir,
1800+
capture_stdout=True,
1801+
check=False,
1802+
)
17841803
project.git(['remote', 'update', '--prune'], cwd=cache_dir, check=False)
17851804

17861805
def init_project(self, project):

0 commit comments

Comments
 (0)