summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
authorRomaric Jodin <rjodin@google.com>2026-10-29 08:52:04 +0100
committergerrit-scoped@luci-project-accounts.iam.gserviceaccount.com <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2026-11-03 00:10:19 -0800
commit365629015667e04739f59070e745548a728549c8 (patch)
treedc4fee64bdec9157fe232c5689a3763fbcb70057 /project.py
parentb90c7cd8f9e14418c4a486f424fc9afc84d3ff18 (diff)
downloadgit-repo-2.72.tar.gz
upload: add --ignore-remote-commitsv2.72stable
When uploading a branch that merges another remote-tracking branch (such as an upstream branch into the destination branch), ReviewableBranch only excludes the destination tracking branch (^base). As a result, git rev-list walks the merged parent and counts all merged commits even though they already exist on a remote branch, triggering the unusual commit count warning in _VerifyPendingCommits. Add --ignore-remote-commits to `repo upload` to pass --not --remotes to git rev-list in ReviewableBranch so commits already reachable from refs/remotes/* are excluded from the pending commit list. Test: ./run_tests tests/test_project.py tests/test_subcmds_upload.py Change-Id: Ib1fb864982729e20a621144580fe95daa478eaee Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/651284 Tested-by: Romaric Jodin <rjodin@google.com> Reviewed-by: Brian Gan <brgan@google.com> Commit-Queue: Romaric Jodin <rjodin@google.com>
Diffstat (limited to 'project.py')
-rw-r--r--project.py40
1 files changed, 33 insertions, 7 deletions
diff --git a/project.py b/project.py
index 13361d1e3..4b23e8a5f 100644
--- a/project.py
+++ b/project.py
@@ -36,6 +36,7 @@ from color import Coloring
36import error 36import error
37import fetch 37import fetch
38import git_command 38import git_command
39from git_config import Branch
39from git_config import GetSchemeFromUrl 40from git_config import GetSchemeFromUrl
40from git_config import GetUrlCookieFile 41from git_config import GetUrlCookieFile
41from git_config import GitConfig 42from git_config import GitConfig
@@ -180,10 +181,17 @@ class ReviewableBranch:
180 _commit_cache = None 181 _commit_cache = None
181 _base_exists = None 182 _base_exists = None
182 183
183 def __init__(self, project, branch, base): 184 def __init__(
185 self,
186 project: "Project",
187 branch: Branch,
188 base: str,
189 ignore_remote_commits: bool = False,
190 ) -> None:
184 self.project = project 191 self.project = project
185 self.branch = branch 192 self.branch = branch
186 self.base = base 193 self.base = base
194 self.ignore_remote_commits = ignore_remote_commits
187 195
188 @property 196 @property
189 def name(self): 197 def name(self):
@@ -204,6 +212,7 @@ class ReviewableBranch:
204 "--date-order", 212 "--date-order",
205 not_rev(self.base), 213 not_rev(self.base),
206 git_refs.R_HEADS + self.name, 214 git_refs.R_HEADS + self.name,
215 *(("--not", "--remotes") if self.ignore_remote_commits else ()),
207 "--", 216 "--",
208 ) 217 )
209 try: 218 try:
@@ -226,7 +235,10 @@ class ReviewableBranch:
226 def unabbrev_commits(self): 235 def unabbrev_commits(self):
227 r = {} 236 r = {}
228 for commit in self.project.bare_git.rev_list( 237 for commit in self.project.bare_git.rev_list(
229 not_rev(self.base), git_refs.R_HEADS + self.name, "--" 238 not_rev(self.base),
239 git_refs.R_HEADS + self.name,
240 *(("--not", "--remotes") if self.ignore_remote_commits else ()),
241 "--",
230 ): 242 ):
231 r[commit[0:8]] = commit 243 r[commit[0:8]] = commit
232 return r 244 return r
@@ -1424,7 +1436,11 @@ class Project:
1424 if git_refs.R_HEADS + n not in heads: 1436 if git_refs.R_HEADS + n not in heads:
1425 self.bare_git.DeleteRef(name, ref_id) 1437 self.bare_git.DeleteRef(name, ref_id)
1426 1438
1427 def GetUploadableBranches(self, selected_branch=None): 1439 def GetUploadableBranches(
1440 self,
1441 selected_branch: Optional[str] = None,
1442 ignore_remote_commits: bool = False,
1443 ) -> List[ReviewableBranch]:
1428 """List any branches which can be uploaded for review.""" 1444 """List any branches which can be uploaded for review."""
1429 if selected_branch: 1445 if selected_branch:
1430 branch = self.GetBranch(selected_branch) 1446 branch = self.GetBranch(selected_branch)
@@ -1436,7 +1452,9 @@ class Project:
1436 pub_id = self.bare_ref.get(git_refs.R_PUB + selected_branch) 1452 pub_id = self.bare_ref.get(git_refs.R_PUB + selected_branch)
1437 if pub_id and pub_id == head_id: 1453 if pub_id and pub_id == head_id:
1438 return [] 1454 return []
1439 rb = self.GetUploadableBranch(selected_branch) 1455 rb = self.GetUploadableBranch(
1456 selected_branch, ignore_remote_commits=ignore_remote_commits
1457 )
1440 if rb: 1458 if rb:
1441 rb.branch.current = selected_branch == self.CurrentBranch 1459 rb.branch.current = selected_branch == self.CurrentBranch
1442 return [rb] 1460 return [rb]
@@ -1454,18 +1472,26 @@ class Project:
1454 if branch_config.published == branch_config.revision: 1472 if branch_config.published == branch_config.revision:
1455 continue 1473 continue
1456 1474
1457 rb = self.GetUploadableBranch(branch) 1475 rb = self.GetUploadableBranch(
1476 branch, ignore_remote_commits=ignore_remote_commits
1477 )
1458 if rb: 1478 if rb:
1459 rb.branch.current = branch_config.current 1479 rb.branch.current = branch_config.current
1460 ready.append(rb) 1480 ready.append(rb)
1461 return ready 1481 return ready
1462 1482
1463 def GetUploadableBranch(self, branch_name): 1483 def GetUploadableBranch(
1484 self,
1485 branch_name: Optional[str],
1486 ignore_remote_commits: bool = False,
1487 ) -> Optional[ReviewableBranch]:
1464 """Get a single uploadable branch, or None.""" 1488 """Get a single uploadable branch, or None."""
1465 branch = self.GetBranch(branch_name) 1489 branch = self.GetBranch(branch_name)
1466 base = branch.LocalMerge 1490 base = branch.LocalMerge
1467 if branch.LocalMerge: 1491 if branch.LocalMerge:
1468 rb = ReviewableBranch(self, branch, base) 1492 rb = ReviewableBranch(
1493 self, branch, base, ignore_remote_commits=ignore_remote_commits
1494 )
1469 if rb.commits: 1495 if rb.commits:
1470 return rb 1496 return rb
1471 return None 1497 return None