Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

better repo cheeck on clone

  • Loading branch information...
commit 56e30fcf98e6d522227308dad26a06fc5f699dcf 1 parent 800e69b
@caruccio authored
Showing with 16 additions and 12 deletions.
  1. +16 −12 remotes
View
28 remotes
@@ -105,7 +105,7 @@ def add_remote(config, remote, giturl):
for r in remotes:
if remote == r['name']:
r['url'] = giturl
- break
+ return
remotes.append({'name': remote, 'url': giturl})
def del_remote(config, remote):
@@ -125,28 +125,32 @@ def list_remotes(config, status=200):
def run_command(*arguments, **kvargs):
proc = subprocess.Popen(arguments, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kvargs)
- retcode = proc.wait()
- if retcode != 0:
- print_status(status=500, command=arguments, retcode=retcode, stdout=proc.stdout.read(), stderr=proc.stderr.read())
- sys.exit(2)
+ stdout, stderr = proc.communicate()
+ if proc.returncode != 0:
+ print_status(status=500, command=arguments, retcode=proc.returncode, stdout=stdout, stderr=stderr)
+ raise Exception
return proc
+def repo_is_empty():
+ arguments = [ git, 'log', '-1', '--pretty=format:%h' ]
+ proc = subprocess.Popen(arguments, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ stdout, stderr = proc.communicate()
+ return not stdout
+
def clone_remote(config, remote, giturl):
assert config and giturl and project, 'Invalid parameters (%s, %s, %s)' % (config, project, giturl)
- if config['remotes']:
- print_status(status=409, message='project already bound to remote')
+ if not repo_is_empty():
+ print_status(status=409, message='project repository not empty')
sys.exit(2)
tempdir = tempfile.mkdtemp()
try:
run_command(git, 'clone', giturl, project, cwd=tempdir)
run_command(git, 'push', 'git@git.ops.getupcloud.com:%s.git' % project, 'master', cwd=os.path.join(tempdir, project))
+ except Exception:
+ sys.exit(2)
+ finally:
shutil.rmtree(tempdir, ignore_errors=False)
- except Exception, ex:
- shutil.rmtree(tempdir, ignore_errors=False)
- raise
- # clone openshift app git and push it into gitlab project git
- #run_command(git, 'pull', '-s', 'recursive', '-X', 'theirs', giturl, 'master', cwd=project_dir(project))
add_remote(config, remote, giturl)
list_remotes(config, status=201)

0 comments on commit 56e30fc

Please sign in to comment.
Something went wrong with that request. Please try again.