in project.py [0:0]
def UploadForReview(self, branch=None,
people=([], []),
dryrun=False,
auto_topic=False,
hashtags=(),
labels=(),
private=False,
notify=None,
wip=False,
dest_branch=None,
validate_certs=True,
push_options=None):
"""Uploads the named branch for code review.
"""
if branch is None:
branch = self.CurrentBranch
if branch is None:
raise GitError('not currently on a branch')
branch = self.GetBranch(branch)
if not branch.LocalMerge:
raise GitError('branch %s does not track a remote' % branch.name)
if not branch.remote.review:
raise GitError('remote %s has no review url' % branch.remote.name)
if dest_branch is None:
dest_branch = self.dest_branch
if dest_branch is None:
dest_branch = branch.merge
if not dest_branch.startswith(R_HEADS):
dest_branch = R_HEADS + dest_branch
if not branch.remote.projectname:
branch.remote.projectname = self.name
branch.remote.Save()
url = branch.remote.ReviewUrl(self.UserEmail, validate_certs)
if url is None:
raise UploadError('review not configured')
cmd = ['push']
if dryrun:
cmd.append('-n')
if url.startswith('ssh://'):
cmd.append('--receive-pack=gerrit receive-pack')
for push_option in (push_options or []):
cmd.append('-o')
cmd.append(push_option)
cmd.append(url)
if dest_branch.startswith(R_HEADS):
dest_branch = dest_branch[len(R_HEADS):]
ref_spec = '%s:refs/for/%s' % (R_HEADS + branch.name, dest_branch)
opts = []
if auto_topic:
opts += ['topic=' + branch.name]
opts += ['t=%s' % p for p in hashtags]
opts += ['l=%s' % p for p in labels]
opts += ['r=%s' % p for p in people[0]]
opts += ['cc=%s' % p for p in people[1]]
if notify:
opts += ['notify=' + notify]
if private:
opts += ['private']
if wip:
opts += ['wip']
if opts:
ref_spec = ref_spec + '%' + ','.join(opts)
cmd.append(ref_spec)
if GitCommand(self, cmd, bare=True).Wait() != 0:
raise UploadError('Upload failed')
if not dryrun:
msg = "posted to %s for %s" % (branch.remote.review, dest_branch)
self.bare_git.UpdateRef(R_PUB + branch.name,
R_HEADS + branch.name,
message=msg)