diff options
Diffstat (limited to 'subcmds/upload.py')
| -rw-r--r-- | subcmds/upload.py | 56 |
1 files changed, 50 insertions, 6 deletions
diff --git a/subcmds/upload.py b/subcmds/upload.py index e314032a..8d801e08 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py | |||
| @@ -21,19 +21,26 @@ 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 | ||
| 27 | from pyversion import is_python3 | ||
| 28 | if not is_python3(): | ||
| 29 | # pylint:disable=W0622 | ||
| 30 | input = raw_input | ||
| 31 | # pylint:enable=W0622 | ||
| 32 | |||
| 26 | UNUSUAL_COMMIT_THRESHOLD = 5 | 33 | UNUSUAL_COMMIT_THRESHOLD = 5 |
| 27 | 34 | ||
| 28 | def _ConfirmManyUploads(multiple_branches=False): | 35 | def _ConfirmManyUploads(multiple_branches=False): |
| 29 | if multiple_branches: | 36 | if multiple_branches: |
| 30 | print('ATTENTION: One or more branches has an unusually high number' | 37 | print('ATTENTION: One or more branches has an unusually high number ' |
| 31 | 'of commits.') | 38 | 'of commits.') |
| 32 | else: | 39 | else: |
| 33 | print('ATTENTION: You are uploading an unusually high number of commits.') | 40 | print('ATTENTION: You are uploading an unusually high number of commits.') |
| 34 | print('YOU PROBABLY DO NOT MEAN TO DO THIS. (Did you rebase across' | 41 | print('YOU PROBABLY DO NOT MEAN TO DO THIS. (Did you rebase across ' |
| 35 | 'branches?)') | 42 | 'branches?)') |
| 36 | answer = raw_input("If you are sure you intend to do this, type 'yes': ").strip() | 43 | answer = input("If you are sure you intend to do this, type 'yes': ").strip() |
| 37 | return answer == "yes" | 44 | return answer == "yes" |
| 38 | 45 | ||
| 39 | def _die(fmt, *args): | 46 | def _die(fmt, *args): |
| @@ -140,6 +147,10 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ | |||
| 140 | p.add_option('-d', '--draft', | 147 | p.add_option('-d', '--draft', |
| 141 | action='store_true', dest='draft', default=False, | 148 | action='store_true', dest='draft', default=False, |
| 142 | help='If specified, upload as a draft.') | 149 | help='If specified, upload as a draft.') |
| 150 | p.add_option('-D', '--destination', '--dest', | ||
| 151 | type='string', action='store', dest='dest_branch', | ||
| 152 | metavar='BRANCH', | ||
| 153 | help='Submit for review on this target branch.') | ||
| 143 | 154 | ||
| 144 | # Options relating to upload hook. Note that verify and no-verify are NOT | 155 | # Options relating to upload hook. Note that verify and no-verify are NOT |
| 145 | # opposites of each other, which is why they store to different locations. | 156 | # opposites of each other, which is why they store to different locations. |
| @@ -179,7 +190,8 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ | |||
| 179 | date = branch.date | 190 | date = branch.date |
| 180 | commit_list = branch.commits | 191 | commit_list = branch.commits |
| 181 | 192 | ||
| 182 | print('Upload project %s/ to remote branch %s:' % (project.relpath, project.revisionExpr)) | 193 | destination = opt.dest_branch or project.dest_branch or project.revisionExpr |
| 194 | print('Upload project %s/ to remote branch %s:' % (project.relpath, destination)) | ||
| 183 | print(' branch %s (%2d commit%s, %s):' % ( | 195 | print(' branch %s (%2d commit%s, %s):' % ( |
| 184 | name, | 196 | name, |
| 185 | len(commit_list), | 197 | len(commit_list), |
| @@ -213,18 +225,21 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ | |||
| 213 | 225 | ||
| 214 | b = {} | 226 | b = {} |
| 215 | for branch in avail: | 227 | for branch in avail: |
| 228 | if branch is None: | ||
| 229 | continue | ||
| 216 | name = branch.name | 230 | name = branch.name |
| 217 | date = branch.date | 231 | date = branch.date |
| 218 | commit_list = branch.commits | 232 | commit_list = branch.commits |
| 219 | 233 | ||
| 220 | if b: | 234 | if b: |
| 221 | script.append('#') | 235 | script.append('#') |
| 236 | destination = opt.dest_branch or project.dest_branch or project.revisionExpr | ||
| 222 | script.append('# branch %s (%2d commit%s, %s) to remote branch %s:' % ( | 237 | script.append('# branch %s (%2d commit%s, %s) to remote branch %s:' % ( |
| 223 | name, | 238 | name, |
| 224 | len(commit_list), | 239 | len(commit_list), |
| 225 | len(commit_list) != 1 and 's' or '', | 240 | len(commit_list) != 1 and 's' or '', |
| 226 | date, | 241 | date, |
| 227 | project.revisionExpr)) | 242 | destination)) |
| 228 | for commit in commit_list: | 243 | for commit in commit_list: |
| 229 | script.append('# %s' % commit) | 244 | script.append('# %s' % commit) |
| 230 | b[name] = branch | 245 | b[name] = branch |
| @@ -330,7 +345,21 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ | |||
| 330 | key = 'review.%s.uploadtopic' % branch.project.remote.review | 345 | key = 'review.%s.uploadtopic' % branch.project.remote.review |
| 331 | opt.auto_topic = branch.project.config.GetBoolean(key) | 346 | opt.auto_topic = branch.project.config.GetBoolean(key) |
| 332 | 347 | ||
| 333 | branch.UploadForReview(people, auto_topic=opt.auto_topic, draft=opt.draft) | 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 | |||
| 362 | branch.UploadForReview(people, auto_topic=opt.auto_topic, draft=opt.draft, dest_branch=destination) | ||
| 334 | branch.uploaded = True | 363 | branch.uploaded = True |
| 335 | except UploadError as e: | 364 | except UploadError as e: |
| 336 | branch.error = e | 365 | branch.error = e |
| @@ -364,6 +393,21 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ | |||
| 364 | if have_errors: | 393 | if have_errors: |
| 365 | sys.exit(1) | 394 | sys.exit(1) |
| 366 | 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 | |||
| 367 | def Execute(self, opt, args): | 411 | def Execute(self, opt, args): |
| 368 | project_list = self.GetProjects(args) | 412 | project_list = self.GetProjects(args) |
| 369 | pending = [] | 413 | pending = [] |
