wipe git clone on errors (#30720)
This commit is contained in:
parent
3b0463c4ce
commit
8a98a2a49f
|
@ -3,6 +3,7 @@
|
|||
import atexit
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tarfile
|
||||
import time
|
||||
|
@ -390,6 +391,44 @@ def clean_git_on_exit(git_project_path):
|
|||
if os.path.exists(changelog_tmp):
|
||||
os.remove(changelog_tmp)
|
||||
|
||||
def setup_git_tree(project_name, options):
|
||||
git_project_path = os.path.join(settings.GIT_PATH, os.path.basename(project_name))
|
||||
if options.branch.startswith('wip/'):
|
||||
if os.path.exists(git_project_path):
|
||||
shutil.rmtree(git_project_path)
|
||||
if os.path.exists(git_project_path):
|
||||
existing_tree = True
|
||||
os.chdir(git_project_path)
|
||||
try:
|
||||
subprocess.check_call(['git', 'checkout', '--quiet', options.branch])
|
||||
subprocess.check_call(['git', 'reset', '--hard', 'origin/%s' % options.branch])
|
||||
except subprocess.CalledProcessError as e:
|
||||
print >> sys.stderr, e
|
||||
shutil.rmtree(git_project_path)
|
||||
return setup_git_tree(project_name, options)
|
||||
else:
|
||||
existing_tree = False
|
||||
os.chdir(settings.GIT_PATH)
|
||||
if project_name.startswith('/'):
|
||||
call("git clone %s" % project_name)
|
||||
else:
|
||||
call("git clone %s/%s.git" % \
|
||||
(settings.GIT_REPOSITORY_URL, project_name))
|
||||
|
||||
os.chdir(git_project_path)
|
||||
try:
|
||||
subprocess.check_call(['git', 'checkout', '--quiet', options.branch])
|
||||
subprocess.check_call(['git', 'pull'])
|
||||
subprocess.check_call(['git', 'submodule', 'init'])
|
||||
subprocess.check_call(['git', 'submodule', 'update'])
|
||||
except subprocess.CalledProcessError as e:
|
||||
if existing_tree:
|
||||
print >> sys.stderr, e
|
||||
shutil.rmtree(git_project_path)
|
||||
return setup_git_tree(project_name, options)
|
||||
raise
|
||||
|
||||
|
||||
def main():
|
||||
options, args = parse_cmdline()
|
||||
for method in options.cleaning:
|
||||
|
@ -405,13 +444,9 @@ def main():
|
|||
if options.branch.startswith('origin/'):
|
||||
# normalize without origin/
|
||||
options.branch = options.branch[len('origin/'):]
|
||||
if options.branch.startswith('wip/'):
|
||||
if os.path.exists(git_project_path):
|
||||
shutil.rmtree(git_project_path)
|
||||
if os.path.exists(git_project_path):
|
||||
existing_tree = os.path.exists(git_project_path)
|
||||
if existing_tree:
|
||||
os.chdir(git_project_path)
|
||||
call("git checkout --quiet %s" % options.branch)
|
||||
call("git reset --hard origin/%s" % options.branch)
|
||||
last_tag = output("git describe --abbrev=0 --tags --match=v*",
|
||||
exit_on_error=False)
|
||||
if last_tag:
|
||||
|
@ -420,18 +455,7 @@ def main():
|
|||
last_tag = "0.0"
|
||||
else:
|
||||
last_tag = "0.0"
|
||||
os.chdir(settings.GIT_PATH)
|
||||
if project_name.startswith('/'):
|
||||
call("git clone %s" % project_name)
|
||||
else:
|
||||
call("git clone %s/%s.git" % \
|
||||
(settings.GIT_REPOSITORY_URL, project_name))
|
||||
print "+ Updating git repository and parsing configuration ..."
|
||||
os.chdir(git_project_path)
|
||||
call("git checkout --quiet %s" % options.branch)
|
||||
call("git pull")
|
||||
call("git submodule init")
|
||||
call("git submodule update")
|
||||
setup_git_tree(project_name, options)
|
||||
project = get_project_infos(git_project_path, options)
|
||||
|
||||
if not os.path.exists(project['lock_path']):
|
||||
|
|
Loading…
Reference in New Issue