Skip to content

Commit 41b9cea

Browse files
ninlootSebastian Thiel
authored and
Sebastian Thiel
committed
Add support to pass clone options that can be repeated multiple times
1 parent 31cc047 commit 41b9cea

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

Diff for: AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ Contributors are:
3030
-William Luc Ritchie
3131
-David Host <hostdm _at_ outlook.com>
3232
-A. Jesse Jiryu Davis <jesse _at_ emptysquare.net>
33+
-Steven Whitman <ninloot _at_ gmail.com>
3334

3435
Portions derived from other open source works and are clearly marked.

Diff for: git/repo/base.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ def init(cls, path=None, mkdir=True, odbt=GitCmdObjectDB, expand_vars=True, **kw
931931
return cls(path, odbt=odbt)
932932

933933
@classmethod
934-
def _clone(cls, git, url, path, odb_default_type, progress, **kwargs):
934+
def _clone(cls, git, url, path, odb_default_type, progress, multi_options=None, **kwargs):
935935
if progress is not None:
936936
progress = to_progress_instance(progress)
937937

@@ -953,7 +953,10 @@ def _clone(cls, git, url, path, odb_default_type, progress, **kwargs):
953953
sep_dir = kwargs.get('separate_git_dir')
954954
if sep_dir:
955955
kwargs['separate_git_dir'] = Git.polish_url(sep_dir)
956-
proc = git.clone(Git.polish_url(url), clone_path, with_extended_output=True, as_process=True,
956+
multi = None
957+
if multi_options:
958+
multi = ' '.join(multi_options).split(' ')
959+
proc = git.clone(multi, Git.polish_url(url), clone_path, with_extended_output=True, as_process=True,
957960
v=True, universal_newlines=True, **add_progress(kwargs, git, progress))
958961
if progress:
959962
handle_process_output(proc, None, progress.new_message_handler(), finalize_process, decode_streams=False)
@@ -983,33 +986,38 @@ def _clone(cls, git, url, path, odb_default_type, progress, **kwargs):
983986
# END handle remote repo
984987
return repo
985988

986-
def clone(self, path, progress=None, **kwargs):
989+
def clone(self, path, progress=None, multi_options=None, **kwargs):
987990
"""Create a clone from this repository.
988991
989992
:param path: is the full path of the new repo (traditionally ends with ./<name>.git).
990993
:param progress: See 'git.remote.Remote.push'.
994+
:param multi_options: A list of Clone options that can be provided multiple times. One
995+
option per list item which is passed exactly as specified to clone.
996+
For example ['--config core.filemode=false', '--config core.ignorecase',
997+
'--recurse-submodule=repo1_path', '--recurse-submodule=repo2_path']
991998
:param kwargs:
992999
* odbt = ObjectDatabase Type, allowing to determine the object database
9931000
implementation used by the returned Repo instance
9941001
* All remaining keyword arguments are given to the git-clone command
9951002
9961003
:return: ``git.Repo`` (the newly cloned repo)"""
997-
return self._clone(self.git, self.common_dir, path, type(self.odb), progress, **kwargs)
1004+
return self._clone(self.git, self.common_dir, path, type(self.odb), progress, multi_options, **kwargs)
9981005

9991006
@classmethod
1000-
def clone_from(cls, url, to_path, progress=None, env=None, **kwargs):
1007+
def clone_from(cls, url, to_path, progress=None, env=None, multi_options=None, **kwargs):
10011008
"""Create a clone from the given URL
10021009
10031010
:param url: valid git url, see http://www.kernel.org/pub/software/scm/git/docs/git-clone.html#URLS
10041011
:param to_path: Path to which the repository should be cloned to
10051012
:param progress: See 'git.remote.Remote.push'.
10061013
:param env: Optional dictionary containing the desired environment variables.
1014+
:param mutli_options: See ``clone`` method
10071015
:param kwargs: see the ``clone`` method
10081016
:return: Repo instance pointing to the cloned directory"""
10091017
git = Git(os.getcwd())
10101018
if env is not None:
10111019
git.update_environment(**env)
1012-
return cls._clone(git, url, to_path, GitCmdObjectDB, progress, **kwargs)
1020+
return cls._clone(git, url, to_path, GitCmdObjectDB, progress, multi_options, **kwargs)
10131021

10141022
def archive(self, ostream, treeish=None, prefix=None, **kwargs):
10151023
"""Archive the tree at the given revision.

Diff for: git/test/test_repo.py

+16
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,22 @@ def test_clone_from_pathlib(self, rw_dir):
229229

230230
Repo.clone_from(original_repo.git_dir, pathlib.Path(rw_dir) / "clone_pathlib")
231231

232+
@with_rw_directory
233+
def test_clone_from_pathlib_withConfig(self, rw_dir):
234+
if pathlib is None: # pythons bellow 3.4 don't have pathlib
235+
raise SkipTest("pathlib was introduced in 3.4")
236+
237+
original_repo = Repo.init(osp.join(rw_dir, "repo"))
238+
239+
cloned = Repo.clone_from(original_repo.git_dir, pathlib.Path(rw_dir) / "clone_pathlib_withConfig",
240+
multi_options=["--recurse-submodules=repo",
241+
"--config core.filemode=false",
242+
"--config submodule.repo.update=checkout"])
243+
244+
assert_equal(cloned.config_reader().get_value('submodule', 'active'), 'repo')
245+
assert_equal(cloned.config_reader().get_value('core', 'filemode'), False)
246+
assert_equal(cloned.config_reader().get_value('submodule "repo"', 'update'), 'checkout')
247+
232248
@with_rw_repo('HEAD')
233249
def test_max_chunk_size(self, repo):
234250
class TestOutputStream(object):

0 commit comments

Comments
 (0)