info: Report actual checked-out HEAD revision

When `repo info` runs, the reported "Current revision" is resolved using
the manifest's target branch tracking ref (e.g. refs/remotes/goog/main).

Introduce Project.GetHeadRevisionId(), which gets the checked-out HEAD
commit in the worktree, and use it in `repo info` with a fallback to the
old behavior if the project is not checked out.

Bug: 526685287
Change-Id: I72280ce27daa210cada27d722a94e365644f06e0
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/599481
Reviewed-by: Brian Gan <brgan@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Tested-by: Gavin Mak <gavinmak@google.com>
This commit is contained in:
Gavin Mak
2026-06-22 22:36:20 +00:00
committed by gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com
parent c21a41c7cc
commit 88a7e88e54
4 changed files with 61 additions and 2 deletions
+12
View File
@@ -1647,6 +1647,18 @@ class Project:
f"revision {self.revisionExpr} in {self.name} not found"
)
def GetHeadRevisionId(self) -> Optional[str]:
"""Get the commit revision of the checked out HEAD.
Returns None if worktree is not checked out or HEAD cannot be resolved.
"""
if self.work_git:
try:
return self.work_git.rev_parse("HEAD")
except GitError:
pass
return None
def GetRevisionId(self, all_refs=None):
if self.revisionId:
return self.revisionId