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:
parent
07d83e1dbe
commit
2673e8ca87
|
@ -503,8 +503,15 @@ def _fetch(project):
|
||||||
|
|
||||||
msg = 'Cloning (name-and-path)'
|
msg = 'Cloning (name-and-path)'
|
||||||
cmd = 'clone'
|
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)'
|
cmd += ' --branch (revision)'
|
||||||
|
checkout = False
|
||||||
if project.clone_depth:
|
if project.clone_depth:
|
||||||
msg += ' with --depth (clone-depth)'
|
msg += ' with --depth (clone-depth)'
|
||||||
cmd += ' --depth (clone-depth)'
|
cmd += ' --depth (clone-depth)'
|
||||||
|
@ -513,6 +520,9 @@ def _fetch(project):
|
||||||
_inf(project, msg)
|
_inf(project, msg)
|
||||||
_git_base(project, cmd)
|
_git_base(project, cmd)
|
||||||
|
|
||||||
|
if checkout:
|
||||||
|
_checkout(project, project.revision)
|
||||||
|
|
||||||
# Update manifest-rev branch
|
# Update manifest-rev branch
|
||||||
_git(project,
|
_git(project,
|
||||||
'update-ref refs/heads/(manifest-rev-branch) {}'.format(
|
'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,
|
res = _git(project, 'rev-parse --show-cdup', capture_stdout=True,
|
||||||
check=False)
|
check=False)
|
||||||
|
|
||||||
return handle(not(res.returncode or res.stdout))
|
return handle(not (res.returncode or res.stdout))
|
||||||
|
|
||||||
|
|
||||||
def _branches(project):
|
def _branches(project):
|
||||||
|
|
Loading…
Reference in New Issue