Skip to content

Commit

Permalink
Merge branch 'Liambeguin-submodule-depth'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed May 4, 2020
2 parents e236853 + 18dd177 commit c2fd537
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ Contributors are:
-Dries Kennes <admin _at_ dries007.net>
-Pratik Anurag <panurag247365 _at_ gmail.com>
-Harmon <harmon.public _at_ gmail.com>
-Liam Beguin <liambeguin _at_ gmail.com>
Portions derived from other open source works and are clearly marked.
10 changes: 9 additions & 1 deletion git/objects/submodule/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"""
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions git/test/test_submodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,3 +936,12 @@ 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

@skipIf(True, 'for some unknown reason the assertion fails, even though it in fact is working in more common setup')
@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)
self.assertEqual(len(list(sm.module().iter_commits())), sm_depth)

0 comments on commit c2fd537

Please sign in to comment.