diff options
Diffstat (limited to 'subcmds')
| -rw-r--r-- | subcmds/upload.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/subcmds/upload.py b/subcmds/upload.py index 74c287d0..8d801e08 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py | |||
| @@ -21,6 +21,7 @@ import sys | |||
| 21 | from command import InteractiveCommand | 21 | from command import InteractiveCommand |
| 22 | from editor import Editor | 22 | from editor import Editor |
| 23 | from error import HookError, UploadError | 23 | from error import HookError, UploadError |
| 24 | from git_command import GitCommand | ||
| 24 | from project import RepoHook | 25 | from project import RepoHook |
| 25 | 26 | ||
| 26 | from pyversion import is_python3 | 27 | from pyversion import is_python3 |
| @@ -345,6 +346,19 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ | |||
| 345 | opt.auto_topic = branch.project.config.GetBoolean(key) | 346 | opt.auto_topic = branch.project.config.GetBoolean(key) |
| 346 | 347 | ||
| 347 | destination = opt.dest_branch or branch.project.dest_branch | 348 | destination = opt.dest_branch or branch.project.dest_branch |
| 349 | |||
| 350 | # Make sure our local branch is not setup to track a different remote branch | ||
| 351 | merge_branch = self._GetMergeBranch(branch.project) | ||
| 352 | full_dest = 'refs/heads/%s' % destination | ||
| 353 | if not opt.dest_branch and merge_branch and merge_branch != full_dest: | ||
| 354 | print('merge branch %s does not match destination branch %s' | ||
| 355 | % (merge_branch, full_dest)) | ||
| 356 | print('skipping upload.') | ||
| 357 | print('Please use `--destination %s` if this is intentional' | ||
| 358 | % destination) | ||
| 359 | branch.uploaded = False | ||
| 360 | continue | ||
| 361 | |||
| 348 | branch.UploadForReview(people, auto_topic=opt.auto_topic, draft=opt.draft, dest_branch=destination) | 362 | branch.UploadForReview(people, auto_topic=opt.auto_topic, draft=opt.draft, dest_branch=destination) |
| 349 | branch.uploaded = True | 363 | branch.uploaded = True |
| 350 | except UploadError as e: | 364 | except UploadError as e: |
| @@ -379,6 +393,21 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ | |||
| 379 | if have_errors: | 393 | if have_errors: |
| 380 | sys.exit(1) | 394 | sys.exit(1) |
| 381 | 395 | ||
| 396 | def _GetMergeBranch(self, project): | ||
| 397 | p = GitCommand(project, | ||
| 398 | ['rev-parse', '--abbrev-ref', 'HEAD'], | ||
| 399 | capture_stdout = True, | ||
| 400 | capture_stderr = True) | ||
| 401 | p.Wait() | ||
| 402 | local_branch = p.stdout.strip() | ||
| 403 | p = GitCommand(project, | ||
| 404 | ['config', '--get', 'branch.%s.merge' % local_branch], | ||
| 405 | capture_stdout = True, | ||
| 406 | capture_stderr = True) | ||
| 407 | p.Wait() | ||
| 408 | merge_branch = p.stdout.strip() | ||
| 409 | return merge_branch | ||
| 410 | |||
| 382 | def Execute(self, opt, args): | 411 | def Execute(self, opt, args): |
| 383 | project_list = self.GetProjects(args) | 412 | project_list = self.GetProjects(args) |
| 384 | pending = [] | 413 | pending = [] |
