From fd6edc71b65b7667ccd9415e8247d07e5cc34843 Mon Sep 17 00:00:00 2001 From: Scott Lee Date: Wed, 21 May 2025 23:23:59 +0000 Subject: [PATCH] up Change-Id: I5d1c709518d76d777a7f07c4c774569773c5a265 --- git_superproject.py | 24 ++++++++++++++++++++++++ subcmds/status.py | 12 ++++++++++++ 2 files changed, 36 insertions(+) diff --git a/git_superproject.py b/git_superproject.py index aba836a3c..649fc8d2a 100644 --- a/git_superproject.py +++ b/git_superproject.py @@ -129,6 +129,30 @@ class Superproject: """Set the _print_messages attribute.""" self._print_messages = value + @property + def commit_id(self): + """Returns the commit ID of the superproject checkout.""" + cmd = ["rev-parse", self.revision] + p = GitCommand( + None, # project + cmd, + gitdir=self._work_git, + bare=True, + capture_stdout=True, + capture_stderr=True, + ) + retval = p.Wait() + if retval == 0: + data = p.stdout + else: + self._LogWarning( + "git rev-parse call failed, command: git {}, " + "return code: {}, stderr: {}", + cmd, + p.stdwerr, + ) + return data + @property def project_commit_ids(self): """Returns a dictionary of projects and their commit ids.""" diff --git a/subcmds/status.py b/subcmds/status.py index cda73627f..95ffa6a18 100644 --- a/subcmds/status.py +++ b/subcmds/status.py @@ -87,6 +87,12 @@ the following meanings: help="include objects in working directory outside of repo " "projects", ) + p.add_option( + "--superproject-hash", + dest="superproject_hash", + action="store_true", + help="print the superproject hash", + ) @classmethod def _StatusHelper(cls, quiet, local, project_idx): @@ -132,6 +138,12 @@ the following meanings: outstring.append("".join([status_header, item, "/"])) def Execute(self, opt, args): + if opt.superproject_hash: + sp = self.manifest.superproject + shash = sp.commit_id if sp else "None" + print("Superproject Hash:", shash) + return + all_projects = self.GetProjects( args, all_manifests=not opt.this_manifest_only )