From 809c7911944bc32223a41ea3cecc051d698d0503 Mon Sep 17 00:00:00 2001 From: Liam Beguin Date: Sat, 2 May 2020 15:30:44 -0400 Subject: [PATCH 1/3] add myself to AUTHORS Signed-off-by: Liam Beguin --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index d8ebb76b0..e24e8f4dd 100644 --- a/AUTHORS +++ b/AUTHORS @@ -40,4 +40,5 @@ Contributors are: -Dries Kennes -Pratik Anurag -Harmon +-Liam Beguin Portions derived from other open source works and are clearly marked. From 09a96fb2ea908e20d5acb7445d542fa2f8d10bb6 Mon Sep 17 00:00:00 2001 From: Liam Beguin Date: Sat, 2 May 2020 15:31:03 -0400 Subject: [PATCH 2/3] add test case for submodule depth parameter Signed-off-by: Liam Beguin --- git/test/test_submodule.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/git/test/test_submodule.py b/git/test/test_submodule.py index 9dd439347..08d30ee79 100644 --- a/git/test/test_submodule.py +++ b/git/test/test_submodule.py @@ -936,3 +936,11 @@ class Repo(object): relative_path = Submodule._to_relative_path(super_repo, submodule_path) msg = '_to_relative_path should be "submodule_path" but was "%s"' % relative_path assert relative_path == 'submodule_path', msg + + @with_rw_directory + def test_depth(self, rwdir): + parent = git.Repo.init(osp.join(rwdir, 'test_depth')) + sm_name = 'mymodules/myname' + sm_depth = 1 + sm = parent.create_submodule(sm_name, sm_name, url=self._small_repo_url(), depth=sm_depth) + assert len(list(sm.module().iter_commits())) == sm_depth From d6e1dcc992ff0a8ddcb4bca281ae34e9bc0df34b Mon Sep 17 00:00:00 2001 From: Liam Beguin Date: Sat, 2 May 2020 14:37:58 -0400 Subject: [PATCH 3/3] allow setting depth when cloning a submodule Signed-off-by: Liam Beguin --- git/objects/submodule/base.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py index f41ec13b6..4629f82d5 100644 --- a/git/objects/submodule/base.py +++ b/git/objects/submodule/base.py @@ -309,7 +309,7 @@ def _write_git_file_and_module_config(cls, working_tree_dir, module_abspath): #{ Edit Interface @classmethod - def add(cls, repo, name, path, url=None, branch=None, no_checkout=False): + def add(cls, repo, name, path, url=None, branch=None, no_checkout=False, depth=None): """Add a new submodule to the given repository. This will alter the index as well as the .gitmodules file, but will not create a new commit. If the submodule already exists, no matter if the configuration differs @@ -334,6 +334,8 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False): Examples are 'master' or 'feature/new' :param no_checkout: if True, and if the repository has to be cloned manually, no checkout will be performed + :param depth: Create a shallow clone with a history truncated to the + specified number of commits. :return: The newly created submodule instance :note: works atomically, such that no change will be done if the repository update fails for instance""" @@ -395,6 +397,12 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False): kwargs['b'] = br.name # END setup checkout-branch + if depth: + if isinstance(depth, int): + kwargs['depth'] = depth + else: + raise ValueError("depth should be an integer") + # _clone_repo(cls, repo, url, path, name, **kwargs): mrepo = cls._clone_repo(repo, url, path, name, **kwargs) # END verify url