project: Avoid skipping fetches for shallow clones without .git/shallow

When optimizing fetches for projects with immutable revisions, the fetch
should not be skipped if the project is configured for a shallow clone
(depth > 0) but the .git/shallow file is missing. The absence of the
.git/shallow file means the repository is not a shallow clone, or the
shallow clone is incomplete, so a fetch is necessary to ensure the
revision is present.

Bug: 503081454
Change-Id: Ic3549612bcd69050a926652ee4e522c79ad8124c
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/573821
Tested-by: Becky Siegel <beckysiegel@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Becky Siegel <beckysiegel@google.com>
This commit is contained in:
Becky Siegel
2026-04-15 20:16:52 -07:00
parent 8869a30283
commit b43a20b859
2 changed files with 118 additions and 0 deletions
+7
View File
@@ -1495,6 +1495,10 @@ class Project:
and self._CheckForImmutableRevision(
use_superproject=use_superproject
)
and (
not depth
or os.path.exists(os.path.join(self.gitdir, "shallow"))
)
):
remote_fetched = True
try:
@@ -2616,6 +2620,9 @@ class Project:
if is_sha1 or tag_name is not None:
if self._CheckForImmutableRevision(
use_superproject=use_superproject
) and (
not depth
or os.path.exists(os.path.join(self.gitdir, "shallow"))
):
if verbose:
print(