diff --git a/platformio/package/manager/_update.py b/platformio/package/manager/_update.py index c5ae3d8d..5d689ba6 100644 --- a/platformio/package/manager/_update.py +++ b/platformio/package/manager/_update.py @@ -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 ) diff --git a/platformio/package/vcsclient.py b/platformio/package/vcsclient.py index adbcd6f5..d7c6b94a 100644 --- a/platformio/package/vcsclient.py +++ b/platformio/package/vcsclient.py @@ -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