| |
@@ -1474,7 +1474,7 @@
|
| |
return
|
| |
|
| |
def clone(self, repo, path=None, branch=None, bare_dir=None,
|
| |
- anon=False, target=None):
|
| |
+ anon=False, target=None, depth=None):
|
| |
"""Clone a repo, optionally check out a specific branch.
|
| |
|
| |
:param str repo: the name of the repository to clone.
|
| |
@@ -1487,6 +1487,8 @@
|
| |
`False`.
|
| |
:param str target: an optional name of the folder in which to clone the
|
| |
repo.
|
| |
+ :param int depth: create a shallow clone with a history truncated
|
| |
+ to the specified number of commits.
|
| |
"""
|
| |
|
| |
if not path:
|
| |
@@ -1503,6 +1505,10 @@
|
| |
cmd = ['git', 'clone']
|
| |
if self.quiet:
|
| |
cmd.append('-q')
|
| |
+ if depth:
|
| |
+ # argument '--depth' goes with '--no-single-branch' together
|
| |
+ # to apply history truncation to all cloned branches
|
| |
+ cmd.extend(['--depth', depth, "--no-single-branch"])
|
| |
# do the clone
|
| |
if branch and bare_dir:
|
| |
raise rpkgError('Cannot combine bare cloning with a branch')
|
| |
@@ -1548,7 +1554,7 @@
|
| |
return repo.split("/")[-1]
|
| |
return repo
|
| |
|
| |
- def clone_with_dirs(self, repo, anon=False, target=None):
|
| |
+ def clone_with_dirs(self, repo, anon=False, target=None, depth=None):
|
| |
"""Clone a repo old style with subdirs for each branch.
|
| |
|
| |
:param str repo: name of the repository to clone.
|
| |
@@ -1556,6 +1562,8 @@
|
| |
`False`.
|
| |
:param str target: an optional name of the folder in which to clone the
|
| |
repo.
|
| |
+ :param int depth: create a shallow clone with a history truncated
|
| |
+ to the specified number of commits.
|
| |
"""
|
| |
|
| |
self._push_url = None
|
| |
@@ -1581,7 +1589,7 @@
|
| |
|
| |
# Create a bare clone first. This gives us a good list of branches
|
| |
try:
|
| |
- self.clone(repo, top_path, bare_dir=repo_path, anon=anon)
|
| |
+ self.clone(repo, top_path, bare_dir=repo_path, anon=anon, depth=depth)
|
| |
except Exception as e:
|
| |
# Clean out our directory
|
| |
shutil.rmtree(top_path)
|
| |
Added '--depth' argument for 'git clone' command. It creates a shallow clone
with a history truncated to the specified number of commits. Additional
parameter '--no-single-branch' is added together with '--depth' to apply
history truncation to all cloned branches.
JIRA: COMPOSE-2812
Fixes: #363
Signed-off-by: Ondrej Nosek onosek@redhat.com