Commit 9fff941c authored by Jérome Perrin's avatar Jérome Perrin

gitclone: refuse deleting a working copy with local commits or changes

parent 83632948
Changes
=======
* gitclone: do not delete the working copy if develop is set
0.12 (2013-09-05)
-----------------
......
......@@ -40,5 +40,9 @@ setup(name=name,
'download-unpacked = slapos.recipe.downloadunpacked:Recipe',
'gitclone = slapos.recipe.gitclone:Recipe',
'npm = slapos.recipe.npm:Npm',
]},
],
'zc.buildout.uninstall': [
'gitclone = slapos.recipe.gitclone:uninstall',
],
},
)
......@@ -33,6 +33,7 @@ import traceback
from zc.buildout import UserError
from subprocess import check_call, CalledProcessError
import subprocess
try:
try:
......@@ -167,8 +168,13 @@ class Recipe(object):
"""
# If directory already exist: delete it.
if os.path.exists(self.location):
print 'destination directory already exists. Deleting it.'
shutil.rmtree(self.location)
print 'destination directory already exists.'
if not self.develop:
print 'Deleting it.'
shutil.rmtree(self.location)
else:
# If develop is set, assume that this is a valid working copy
return [self.location]
git_clone_command = [self.git_command, 'clone',
self.repository,
......@@ -234,3 +240,30 @@ class Recipe(object):
self.gitReset(self.revision)
else:
self.gitReset('@{upstream}')
def uninstall(name, options):
"""Keep the working copy if develop is set to true.
"""
force_keep = False
if options.get('develop', 'no').lower() in ('1', 'yes', 'true'):
p = subprocess.Popen([options.get('git_command', 'git'), 'status', '--short'],
cwd=options['location'],
stdout=subprocess.PIPE)
if p.communicate()[0].strip():
print "You have uncommited changes in %s. "\
"This folder will be left as is." % options['location']
force_keep = True
p = subprocess.Popen([options.get('git_command', 'git'),
'log', '--branches', '--not', '--remotes'],
cwd=options['location'],
stdout=subprocess.PIPE)
if p.communicate()[0].strip():
print "You have commits not pushed upstream in %s. "\
"This folder will be left as is." % options['location']
force_keep = True
if force_keep:
# Eventhough this behaviour is not documented, buildout won't uninstall
# anything if we unset __buildout_installed__
options['__buildout_installed__'] = ''
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment