diff options
| author | Conley Owens <cco3@android.com> | 2013-09-30 15:54:38 -0700 |
|---|---|---|
| committer | Conley Owens <cco3@android.com> | 2013-10-10 09:06:38 -0700 |
| commit | 3bfd72158c11583213037ddfe5224c2038288383 (patch) | |
| tree | 7065b7e5d905aac5e1474c2b2069629a0d52c86e /subcmds/upload.py | |
| parent | 59b31cb6e02b68450f2a5f96bdeffc2a7452d98c (diff) | |
| download | git-repo-3bfd72158c11583213037ddfe5224c2038288383.tar.gz | |
Don't upload when dest branch is not merge branch
Example:
- `repo init -b master` / sync a project
- In one project: `git checkout -b work origin/branch-thats-not-master`
- make some changes, `git commit`
- `repo upload .`
- Upload will now be skipped with a warning instead of being uploaded to
master
Change-Id: I990b36217b75fe3c8b4d776e7fefa1c7d9ab7282
Diffstat (limited to 'subcmds/upload.py')
| -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 = [] |
