From 2673e8ca87bbacf7b8111f683916bb1f4cc48ffa Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Wed, 29 Aug 2018 19:44:31 -0500 Subject: [PATCH] cmd: project: fix edge case when revision is a SHA If the revision is a SHA, we cannot assume the clone command will fetch anything valid, as the remote HEAD may not have been properly initialized. For safety in that case, run a checkout step to ensure the work tree is properly set up. Signed-off-by: Marti Bolivar --- src/west/cmd/project.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/west/cmd/project.py b/src/west/cmd/project.py index f3a81a4..6241448 100644 --- a/src/west/cmd/project.py +++ b/src/west/cmd/project.py @@ -503,8 +503,15 @@ def _fetch(project): msg = 'Cloning (name-and-path)' cmd = 'clone' - if not _is_sha(project.revision): + if _is_sha(project.revision): + # If the project revision is a SHA and the remote repo's + # HEAD doesn't point to anything valid, the clone + # operation might fail to check anything out. In that + # case, make sure to check out the given revision. + checkout = True + else: cmd += ' --branch (revision)' + checkout = False if project.clone_depth: msg += ' with --depth (clone-depth)' cmd += ' --depth (clone-depth)' @@ -513,6 +520,9 @@ def _fetch(project): _inf(project, msg) _git_base(project, cmd) + if checkout: + _checkout(project, project.revision) + # Update manifest-rev branch _git(project, 'update-ref refs/heads/(manifest-rev-branch) {}'.format( @@ -548,7 +558,7 @@ def _cloned(project): res = _git(project, 'rev-parse --show-cdup', capture_stdout=True, check=False) - return handle(not(res.returncode or res.stdout)) + return handle(not (res.returncode or res.stdout)) def _branches(project):