info: print superproject revision

Bug: 416589884
Change-Id: I5d1c709518d76d777a7f07c4c774569773c5a265
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/478205
Lint: Scott Lee <ddoman@google.com>
Tested-by: Scott Lee <ddoman@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
Commit-Queue: Scott Lee <ddoman@google.com>
This commit is contained in:
Scott Lee
2025-05-27 18:36:42 +00:00
committed by LUCI
parent 06338abe79
commit 3c8bae27ec
2 changed files with 29 additions and 1 deletions

View File

@ -129,6 +129,29 @@ class Superproject:
"""Set the _print_messages attribute.""" """Set the _print_messages attribute."""
self._print_messages = value 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:
self._LogWarning(
"git rev-parse call failed, command: git {}, "
"return code: {}, stderr: {}",
cmd,
p.stdwerr,
)
return None
return p.stdout
@property @property
def project_commit_ids(self): def project_commit_ids(self):
"""Returns a dictionary of projects and their commit ids.""" """Returns a dictionary of projects and their commit ids."""
@ -276,7 +299,7 @@ class Superproject:
Works only in git repositories. Works only in git repositories.
Returns: Returns:
data: data returned from 'git ls-tree ...' instead of None. data: data returned from 'git ls-tree ...'. None on error.
""" """
if not os.path.exists(self._work_git): if not os.path.exists(self._work_git):
self._LogWarning( self._LogWarning(
@ -306,6 +329,7 @@ class Superproject:
retval, retval,
p.stderr, p.stderr,
) )
return None
return data return data
def Sync(self, git_event_log): def Sync(self, git_event_log):

View File

@ -102,6 +102,10 @@ class Info(PagedCommand):
self.heading("Manifest groups: ") self.heading("Manifest groups: ")
self.headtext(manifestGroups) self.headtext(manifestGroups)
self.out.nl() self.out.nl()
sp = self.manifest.superproject
srev = sp.commit_id if sp and sp.commit_id else "None"
self.heading("Superproject revision: ")
self.headtext(srev)
self.printSeparator() self.printSeparator()