mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
upload: Skip upload if merge branch doesn't match project revision and
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>
This commit is contained in:
parent
a56e0e17e2
commit
7fa149b47a
@ -484,19 +484,24 @@ Gerrit Code Review: https://www.gerritcodereview.com/
|
|||||||
|
|
||||||
destination = opt.dest_branch or branch.project.dest_branch
|
destination = opt.dest_branch or branch.project.dest_branch
|
||||||
|
|
||||||
# Make sure our local branch is not setup to track a different remote branch
|
if branch.project.dest_branch and not opt.dest_branch:
|
||||||
merge_branch = self._GetMergeBranch(branch.project)
|
|
||||||
if destination:
|
merge_branch = self._GetMergeBranch(
|
||||||
|
branch.project, local_branch=branch.name)
|
||||||
|
|
||||||
full_dest = destination
|
full_dest = destination
|
||||||
if not full_dest.startswith(R_HEADS):
|
if not full_dest.startswith(R_HEADS):
|
||||||
full_dest = R_HEADS + full_dest
|
full_dest = R_HEADS + full_dest
|
||||||
|
|
||||||
if not opt.dest_branch and merge_branch and merge_branch != full_dest:
|
# If the merge branch of the local branch is different from the
|
||||||
print('merge branch %s does not match destination branch %s'
|
# project's revision AND destination, this might not be intentional.
|
||||||
% (merge_branch, full_dest))
|
if (merge_branch and merge_branch != branch.project.revisionExpr
|
||||||
|
and merge_branch != full_dest):
|
||||||
|
print(f'For local branch {branch.name}: merge branch '
|
||||||
|
f'{merge_branch} does not match destination branch '
|
||||||
|
f'{destination}')
|
||||||
print('skipping upload.')
|
print('skipping upload.')
|
||||||
print('Please use `--destination %s` if this is intentional'
|
print(f'Please use `--destination {destination}` if this is intentional')
|
||||||
% destination)
|
|
||||||
branch.uploaded = False
|
branch.uploaded = False
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -546,7 +551,8 @@ Gerrit Code Review: https://www.gerritcodereview.com/
|
|||||||
if have_errors:
|
if have_errors:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def _GetMergeBranch(self, project):
|
def _GetMergeBranch(self, project, local_branch=None):
|
||||||
|
if local_branch is None:
|
||||||
p = GitCommand(project,
|
p = GitCommand(project,
|
||||||
['rev-parse', '--abbrev-ref', 'HEAD'],
|
['rev-parse', '--abbrev-ref', 'HEAD'],
|
||||||
capture_stdout=True,
|
capture_stdout=True,
|
||||||
|
Loading…
Reference in New Issue
Block a user