project: fold normal stash detection into status

When Git 2.35 or newer supplies a stash header, use the same status
snapshot for stateless dirty and stash checks. Retain rev-parse for
earlier clients or when the status snapshot is unavailable.

Bug: 543851900
Bug: 553599402
Change-Id: I6e310459d9c1a3ba7978f7907ae6b7a9bc611749
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/632146
Tested-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Reviewed-by: Brian Gan <brgan@google.com>
This commit is contained in:
Gavin Mak authored and gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com committed 2026-09-21 13:39:51 -07:00
1 parent aaadd5da35
commit 7bffc72b5b
2 files changed
+60 -2

No files matched your search

+16 -1
View File
@@ -930,6 +930,21 @@ class Project:
)
return p.Wait() == 0
def _HasDirtyOrStash(self) -> bool:
"""Check dirty and normal stash state with one status when possible."""
has_status_stash = git_require((2, 35, 0))
status = self._GetStatusSnapshot(
untracked_files="normal",
show_stash=has_status_stash,
)
if status is not None:
if status.is_dirty(consider_untracked=True):
return True
if has_status_stash:
return bool(status.stash_count)
return self.HasStash()
return self.IsDirty(consider_untracked=True) or self.HasStash()
_userident_name = None
_userident_email = None
@@ -1670,7 +1685,7 @@ class Project:
except (GitError, IndexError, ValueError):
return False
if self.IsDirty(consider_untracked=True) or self.HasStash():
if self._HasDirtyOrStash():
return False
return True