Handle different gerrit versions with create-project

Gerrit < 2.12 used a --name argument on create-project. Newer Gerrit
simply takes the project name as an arg. Check the Gerrit version before
constructing the create-project command.

Change-Id: I59ca051627d54a11ef6524cce9b5a4414fd2193d
This commit is contained in:
Clark Boylan 2017-09-19 16:12:05 -07:00
parent d9478fcc08
commit eb6588734c
1 changed files with 23 additions and 1 deletions

View File

@ -221,7 +221,16 @@ class Gerrit(object):
if description:
cmd = "%s --description \"%s\"" % \
(cmd, description.replace('"', r'\"'))
cmd = '%s "%s"' % (cmd, project)
version = None
try:
version = self.parseGerritVersion(self.getVersion())
except Exception:
# If no version then we know version is old and should use --name
pass
if not version or version < (2, 12):
cmd = '%s --name "%s"' % (cmd, project)
else:
cmd = '%s "%s"' % (cmd, project)
out, err = self._ssh(cmd)
return err
@ -275,6 +284,19 @@ class Gerrit(object):
out = out.split(' ')[2]
return out.strip('\n')
def parseGerritVersion(self, version):
# Adapted from gertty setRemoteVersion()
base = version.split('-')[0]
parts = base.split('.')
major = minor = micro = 0
if len(parts) > 0:
major = int(parts[0])
if len(parts) > 1:
minor = int(parts[1])
if len(parts) > 2:
micro = int(parts[2])
return (major, minor, micro)
def replicate(self, project='--all'):
cmd = 'replication start %s' % project
if self.installed_plugins is None: