From c9571423f843340de19ef576ccaa418ac72fdb58 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 11 Jan 2012 14:58:54 -0800 Subject: upload: Support uploading to Gerrit over https:// If SSH is not available, Gerrit returns NOT_AVAILABLE to the /ssh_info query made by repo upload. In this case fallback to the /p/$PROJECT URL that Gerrit also exports and use that for uploads. Change-Id: I1e3e39ab709ecc0a692614a41a42446426f39c08 --- project.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'project.py') diff --git a/project.py b/project.py index 8b9a3fc4..f48472b4 100644 --- a/project.py +++ b/project.py @@ -866,31 +866,30 @@ class Project(object): branch.remote.projectname = self.name branch.remote.Save() - if branch.remote.ReviewProtocol == 'ssh': - if dest_branch.startswith(R_HEADS): - dest_branch = dest_branch[len(R_HEADS):] + url = branch.remote.ReviewUrl(self.UserEmail) + if url is None: + raise UploadError('review not configured') + cmd = ['push'] + if url.startswith('ssh://'): rp = ['gerrit receive-pack'] for e in people[0]: rp.append('--reviewer=%s' % sq(e)) for e in people[1]: rp.append('--cc=%s' % sq(e)) - - ref_spec = '%s:refs/for/%s' % (R_HEADS + branch.name, dest_branch) - if auto_topic: - ref_spec = ref_spec + '/' + branch.name - - cmd = ['push'] cmd.append('--receive-pack=%s' % " ".join(rp)) - cmd.append(branch.remote.SshReviewUrl(self.UserEmail)) - cmd.append(ref_spec) - if GitCommand(self, cmd, bare = True).Wait() != 0: - raise UploadError('Upload failed') + cmd.append(url) - else: - raise UploadError('Unsupported protocol %s' \ - % branch.remote.review) + 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) + if auto_topic: + ref_spec = ref_spec + '/' + branch.name + cmd.append(ref_spec) + + if GitCommand(self, cmd, bare = True).Wait() != 0: + raise UploadError('Upload failed') msg = "posted to %s for %s" % (branch.remote.review, dest_branch) self.bare_git.UpdateRef(R_PUB + branch.name, -- cgit v1.2.3-54-g00ecf