Avoid working with detached / non-existent git branches when checking for updates (#4217)

* Avoid working with detached / non-existent git branches when checking for updates

b/c we can't use `pull` anyway in that situation
Otherwise, ask for the specific branch via `refs/heads/{branch}` and
also fail when it is not available

* Update vcsclient.py

Co-authored-by: Ivan Kravets <me@ikravets.com>
This commit is contained in:
Max Prokhorov
2022-04-08 13:15:35 +03:00
committed by GitHub
parent 1615159014
commit 9097d455db
2 changed files with 17 additions and 6 deletions

View File

@ -72,9 +72,14 @@ class PackageManagerUpdateMixin(object):
return None
if not vcs.can_be_updated:
return None
vcs_revision = vcs.get_latest_revision()
if not vcs_revision:
return None
return str(
self.build_metadata(
pkg.path, pkg.metadata.spec, vcs_revision=vcs.get_latest_revision()
pkg.path, pkg.metadata.spec, vcs_revision=vcs_revision
).version
)

View File

@ -217,12 +217,18 @@ class GitClient(VCSClientBase):
return self.get_current_revision()
branch = self.get_current_branch()
if not branch:
return self.get_current_revision()
result = self.get_cmd_output(["ls-remote"])
return None
branch_ref = f"refs/heads/{branch}"
result = self.get_cmd_output(["ls-remote", self.remote_url, branch_ref])
if not result:
return None
for line in result.split("\n"):
ref_pos = line.strip().find("refs/heads/" + branch)
if ref_pos > 0:
return line[:ref_pos].strip()[:7]
sha, ref = line.strip().split("\t")
if ref == branch_ref:
return sha[:7]
return None