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 <marti@foundries.io>
This commit is contained in:
Marti Bolivar 2018-08-29 19:44:31 -05:00
parent 07d83e1dbe
commit 2673e8ca87
1 changed files with 12 additions and 2 deletions

View File

@ -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):