Skip to content

Submodule depth #1009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 8 additions & 0 deletions git/test/test_submodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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