diff options
| author | Joanna Wang <jojwang@google.com> | 2023-02-24 18:21:34 -0500 |
|---|---|---|
| committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-02-28 14:21:17 +0000 |
| commit | 7fa149b47a980779f02ccaf1d1dbd5af5ce9abc7 (patch) | |
| tree | b8c435f51746c7b295cc1a6e6481d524cb14c6f6 /subcmds | |
| parent | a56e0e17e23f925ff44c75e5b89330ccc2598640 (diff) | |
| download | git-repo-7fa149b47a980779f02ccaf1d1dbd5af5ce9abc7.tar.gz | |
upload: Skip upload if merge branch doesn't match project revision andv2.32
dest_branch.
- This still prevents the case mentioned here:
https://gerrit-review.googlesource.com/c/50300
while also supporting dest_branch.
- Update _GetMergeBranch to get merge branches for any branch, not just
the one we happen to run `repo upload` in. (e.g. for uploading multiple
branches)
Bug: b/27955930
Change-Id: Ia8ee1d6a83a783c984bb2eb308bb11b3a721a95d
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/360794
Commit-Queue: Joanna Wang <jojwang@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Joanna Wang <jojwang@google.com>
Diffstat (limited to 'subcmds')
| -rw-r--r-- | subcmds/upload.py | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/subcmds/upload.py b/subcmds/upload.py index dc7e26da..9c279230 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py | |||
| @@ -484,19 +484,24 @@ Gerrit Code Review: https://www.gerritcodereview.com/ | |||
| 484 | 484 | ||
| 485 | destination = opt.dest_branch or branch.project.dest_branch | 485 | destination = opt.dest_branch or branch.project.dest_branch |
| 486 | 486 | ||
| 487 | # Make sure our local branch is not setup to track a different remote branch | 487 | if branch.project.dest_branch and not opt.dest_branch: |
| 488 | merge_branch = self._GetMergeBranch(branch.project) | 488 | |
| 489 | if destination: | 489 | merge_branch = self._GetMergeBranch( |
| 490 | branch.project, local_branch=branch.name) | ||
| 491 | |||
| 490 | full_dest = destination | 492 | full_dest = destination |
| 491 | if not full_dest.startswith(R_HEADS): | 493 | if not full_dest.startswith(R_HEADS): |
| 492 | full_dest = R_HEADS + full_dest | 494 | full_dest = R_HEADS + full_dest |
| 493 | 495 | ||
| 494 | if not opt.dest_branch and merge_branch and merge_branch != full_dest: | 496 | # If the merge branch of the local branch is different from the |
| 495 | print('merge branch %s does not match destination branch %s' | 497 | # project's revision AND destination, this might not be intentional. |
| 496 | % (merge_branch, full_dest)) | 498 | if (merge_branch and merge_branch != branch.project.revisionExpr |
| 499 | and merge_branch != full_dest): | ||
| 500 | print(f'For local branch {branch.name}: merge branch ' | ||
| 501 | f'{merge_branch} does not match destination branch ' | ||
| 502 | f'{destination}') | ||
| 497 | print('skipping upload.') | 503 | print('skipping upload.') |
| 498 | print('Please use `--destination %s` if this is intentional' | 504 | print(f'Please use `--destination {destination}` if this is intentional') |
| 499 | % destination) | ||
| 500 | branch.uploaded = False | 505 | branch.uploaded = False |
| 501 | continue | 506 | continue |
| 502 | 507 | ||
| @@ -546,13 +551,14 @@ Gerrit Code Review: https://www.gerritcodereview.com/ | |||
| 546 | if have_errors: | 551 | if have_errors: |
| 547 | sys.exit(1) | 552 | sys.exit(1) |
| 548 | 553 | ||
| 549 | def _GetMergeBranch(self, project): | 554 | def _GetMergeBranch(self, project, local_branch=None): |
| 550 | p = GitCommand(project, | 555 | if local_branch is None: |
| 551 | ['rev-parse', '--abbrev-ref', 'HEAD'], | 556 | p = GitCommand(project, |
| 552 | capture_stdout=True, | 557 | ['rev-parse', '--abbrev-ref', 'HEAD'], |
| 553 | capture_stderr=True) | 558 | capture_stdout=True, |
| 554 | p.Wait() | 559 | capture_stderr=True) |
| 555 | local_branch = p.stdout.strip() | 560 | p.Wait() |
| 561 | local_branch = p.stdout.strip() | ||
| 556 | p = GitCommand(project, | 562 | p = GitCommand(project, |
| 557 | ['config', '--get', 'branch.%s.merge' % local_branch], | 563 | ['config', '--get', 'branch.%s.merge' % local_branch], |
| 558 | capture_stdout=True, | 564 | capture_stdout=True, |
