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

gitclone: add depth option

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