From 3c8bae27ecb8a8d95f814430e8985924f770d63b Mon Sep 17 00:00:00 2001 From: Scott Lee Date: Tue, 27 May 2025 18:36:42 +0000 Subject: info: print superproject revision Bug: 416589884 Change-Id: I5d1c709518d76d777a7f07c4c774569773c5a265 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/478205 Lint: Scott Lee Tested-by: Scott Lee Reviewed-by: Mike Frysinger Commit-Queue: Scott Lee --- git_superproject.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'git_superproject.py') diff --git a/git_superproject.py b/git_superproject.py index aba836a3..a557879c 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): -- cgit v1.2.3-54-g00ecf