diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2017-10-01 11:11:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-01 11:11:54 +0200 |
commit | d2ce49598a25b48ad0ab38cc1101c5e2a42a918e (patch) | |
tree | a80bb5ba3ee0c096c55adf33795c8747689e08bd /git | |
parent | ddb828ecd0e28d346934fd1838a5f1c74363fba6 (diff) | |
parent | 55c5f73de7132472e324a02134d4ad8f53bde141 (diff) | |
download | gitpython-d2ce49598a25b48ad0ab38cc1101c5e2a42a918e.tar.gz |
Merge pull request #677 from bpiotr/retaining-env-on-clone
Retaining env on clone_from
Diffstat (limited to 'git')
-rw-r--r-- | git/repo/base.py | 6 | ||||
-rw-r--r-- | git/test/test_repo.py | 9 |
2 files changed, 14 insertions, 1 deletions
diff --git a/git/repo/base.py b/git/repo/base.py index d3bdc983..9ed3f714 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -931,12 +931,16 @@ class Repo(object): if not osp.isabs(path) and git.working_dir: path = osp.join(git._working_dir, path) + repo = cls(path, odbt=odbt) + + # retain env values that were passed to _clone() + repo.git.update_environment(**git.environment()) + # adjust remotes - there may be operating systems which use backslashes, # These might be given as initial paths, but when handling the config file # that contains the remote from which we were clones, git stops liking it # as it will escape the backslashes. Hence we undo the escaping just to be # sure - repo = cls(path, odbt=odbt) if repo.remotes: with repo.remotes[0].config_writer as writer: writer.set_value('url', Git.polish_url(repo.remotes[0].url)) diff --git a/git/test/test_repo.py b/git/test/test_repo.py index 312e67f9..86fb2f51 100644 --- a/git/test/test_repo.py +++ b/git/test/test_repo.py @@ -201,6 +201,15 @@ class TestRepo(TestBase): pass # END test repos with working tree + @with_rw_directory + def test_clone_from_keeps_env(self, rw_dir): + original_repo = Repo.init(osp.join(rw_dir, "repo")) + environment = {"entry1": "value", "another_entry": "10"} + + cloned = Repo.clone_from(original_repo.git_dir, osp.join(rw_dir, "clone"), env=environment) + + assert_equal(environment, cloned.git.environment()) + def test_init(self): prev_cwd = os.getcwd() os.chdir(tempfile.gettempdir()) |