From e47369cd16763ac1fe749ad74c22cb48b3b2db13 Mon Sep 17 00:00:00 2001 From: Scott Lee Date: Tue, 27 May 2025 18:30:56 +0000 Subject: [PATCH] add --superproject-rev for repo status If the option is given, repo status prints the superproject revision Change-Id: I5d1c709518d76d777a7f07c4c774569773c5a265 Bug: 416589884 --- git_superproject.py | 26 +++++++++++++++++++++++++- man/repo-status.1 | 2 +- subcmds/info.py | 4 ++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/git_superproject.py b/git_superproject.py index aba836a3c..a557879c8 100644 --- a/git_superproject.py +++ b/git_superproject.py @@ -129,6 +129,29 @@ 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: + self._LogWarning( + "git rev-parse call failed, command: git {}, " + "return code: {}, stderr: {}", + cmd, + p.stdwerr, + ) + return None + return p.stdout + @property def project_commit_ids(self): """Returns a dictionary of projects and their commit ids.""" @@ -276,7 +299,7 @@ class Superproject: Works only in git repositories. 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): self._LogWarning( @@ -306,6 +329,7 @@ class Superproject: retval, p.stderr, ) + return None return data def Sync(self, git_event_log): diff --git a/man/repo-status.1 b/man/repo-status.1 index db8723fb2..6be14ec63 100644 --- a/man/repo-status.1 +++ b/man/repo-status.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man. -.TH REPO "1" "July 2022" "repo status" "Repo Manual" +.TH REPO "1" "May 2025" "repo status" "Repo Manual" .SH NAME repo \- repo status - manual page for repo status .SH SYNOPSIS diff --git a/subcmds/info.py b/subcmds/info.py index ab230ddd2..461a721c1 100644 --- a/subcmds/info.py +++ b/subcmds/info.py @@ -104,6 +104,10 @@ class Info(PagedCommand): self.heading("Manifest groups: ") self.headtext(manifestGroups) 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()