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 Changes
======= =======
* gitclone: do not delete the working copy if develop is set
0.12 (2013-09-05) 0.12 (2013-09-05)
----------------- -----------------
......
...@@ -40,5 +40,9 @@ setup(name=name, ...@@ -40,5 +40,9 @@ setup(name=name,
'download-unpacked = slapos.recipe.downloadunpacked:Recipe', 'download-unpacked = slapos.recipe.downloadunpacked:Recipe',
'gitclone = slapos.recipe.gitclone:Recipe', 'gitclone = slapos.recipe.gitclone:Recipe',
'npm = slapos.recipe.npm:Npm', 'npm = slapos.recipe.npm:Npm',
]}, ],
'zc.buildout.uninstall': [
'gitclone = slapos.recipe.gitclone:uninstall',
],
},
) )
...@@ -33,6 +33,7 @@ import traceback ...@@ -33,6 +33,7 @@ import traceback
from zc.buildout import UserError from zc.buildout import UserError
from subprocess import check_call, CalledProcessError from subprocess import check_call, CalledProcessError
import subprocess
try: try:
try: try:
...@@ -167,8 +168,13 @@ class Recipe(object): ...@@ -167,8 +168,13 @@ class Recipe(object):
""" """
# If directory already exist: delete it. # If directory already exist: delete it.
if os.path.exists(self.location): if os.path.exists(self.location):
print 'destination directory already exists. Deleting it.' print 'destination directory already exists.'
shutil.rmtree(self.location) 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', git_clone_command = [self.git_command, 'clone',
self.repository, self.repository,
...@@ -234,3 +240,30 @@ class Recipe(object): ...@@ -234,3 +240,30 @@ class Recipe(object):
self.gitReset(self.revision) self.gitReset(self.revision)
else: else:
self.gitReset('@{upstream}') 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