sync: Exclude stateless sync pruned projects from bloat check

If a project has been pruned for stateless sync, it has already
undergone aggressive garbage collection. There should be no bloat
to check for.

Change-Id: I9233a4611e05b7a0b7c097827d6f408144f7380d
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/581841
Tested-by: Gavin Mak <gavinmak@google.com>
Reviewed-by: Becky Siegel <beckysiegel@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 5aec277..b1c3086 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -1459,7 +1459,11 @@
         if not git_require((2, 23, 0)):
             return
 
-        projects = [p for p in projects if p.clone_depth]
+        projects = [
+            p
+            for p in projects
+            if p.clone_depth and not p.stateless_prune_needed
+        ]
         if not projects:
             return
 
diff --git a/tests/test_subcmds_sync.py b/tests/test_subcmds_sync.py
index b3726d2..0a46bbd 100644
--- a/tests/test_subcmds_sync.py
+++ b/tests/test_subcmds_sync.py
@@ -489,6 +489,7 @@
         self.project.name = "project"
         self.project.Exists = True
         self.project.worktree = "worktree"
+        self.project.stateless_prune_needed = False
         self.cmd.git_event_log = mock.MagicMock()
         self.cmd._bloated_projects = []
 
@@ -530,6 +531,21 @@
 
         self.assertEqual(self.cmd._bloated_projects, ["project"])
 
+    @mock.patch("subcmds.sync.git_require")
+    @mock.patch("subcmds.sync.Progress")
+    def test_stateless_prune_excluded(self, mock_progress, mock_git_require):
+        """Test that projects pruned for stateless sync are excluded."""
+        mock_git_require.return_value = True
+        self.project.stateless_prune_needed = True
+
+        self.cmd.ExecuteInParallel = mock.Mock()
+
+        with mock.patch.object(self.cmd, "ParallelContext"):
+            self.cmd._CheckForBloatedProjects([self.project], self.opt)
+
+        self.assertFalse(self.cmd.ExecuteInParallel.called)
+        self.assertEqual(self.cmd._bloated_projects, [])
+
 
 class GCProjectsTest(unittest.TestCase):
     """Tests for Sync._GCProjects."""