Commit 6e4779da authored by Eric Zheng's avatar Eric Zheng

gitclone: add depth option

parent 6d809e51
......@@ -134,7 +134,7 @@ class Recipe(object):
options.setdefault('location',
os.path.join(buildout['buildout']['parts-directory'], name))
self.name = name
for option in ('branch', 'revision', 'location', 'repository'):
for option in ('branch', 'revision', 'location', 'repository', 'depth'):
value = options.get(option, '').strip()
if value == '':
setattr(self, option, None)
......@@ -172,6 +172,14 @@ class Recipe(object):
command.append(revision)
check_call(command, cwd=self.location)
def gitSubmoduleUpdate(self):
"""Updates submodules recursively."""
command = [self.git_command, 'submodule', 'update', '--init',
'--force', '--recursive']
if self.depth != None:
command += '--depth', self.depth
check_call(command, cwd=self.location)
def install(self):
"""
Do a git clone.
......@@ -208,6 +216,8 @@ class Recipe(object):
config.append('core.sparseCheckout=true')
if self.branch:
git_clone_command += '--branch', self.branch
if self.depth != None:
git_clone_command += '--depth', self.depth
if self.ignore_ssl_certificate:
config.append('http.sslVerify=false')
......@@ -240,8 +250,7 @@ class Recipe(object):
if not self.ignore_cloning_submodules:
# Update submodule repository to the commit which is being pointed to
# in main repo
check_call([self.git_command, 'submodule', 'update', '--init',
'--recursive'], cwd=self.location)
self.gitSubmoduleUpdate()
except CalledProcessError:
print("Unable to download from git repository."
" Trying from network cache...")
......@@ -285,7 +294,10 @@ class Recipe(object):
self.deletePycFiles(self.location)
# Fetch and reset to the upstream
check_call([self.git_command, 'fetch', '--all'], cwd=self.location)
update_commend = [self.git_command, 'fetch', '--all']
if self.depth != None:
update_command += '--depth', self.depth
check_call(update_command, cwd=self.location)
self.gitReset('@{upstream}')
if not self.ignore_cloning_submodules:
......@@ -297,8 +309,7 @@ class Recipe(object):
# repo being checked out to the desired one.
# It will also init a submodule if required
# NOTE: This will put the submodule repo in a `Detached` state.
check_call([self.git_command, 'submodule', 'update', '--init', '-f',
'--recursive'], cwd=self.location)
self.gitSubmoduleUpdate()
def uninstall(name, options):
"""Keep the working copy, unless develop is set to false.
......
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