Skip to content

Commit 8a24ccb

Browse files
authored
Merge pull request gitpython-developers#677 from bpiotr/retaining-env-on-clone
Retaining env on clone_from
2 parents 7c76b02 + e4f45e4 commit 8a24ccb

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ Contributors are:
2222
-Anson Mansfield <anson.mansfield _at_ gmail.com>
2323
-Ken Odegard <ken.odegard _at_ gmail.com>
2424
-Alexis Horgix Chotard
25+
-Piotr Babij <piotr.babij _at_ gmail.com>
2526

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

git/repo/base.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -931,12 +931,16 @@ def _clone(cls, git, url, path, odb_default_type, progress, **kwargs):
931931
if not osp.isabs(path) and git.working_dir:
932932
path = osp.join(git._working_dir, path)
933933

934+
repo = cls(path, odbt=odbt)
935+
936+
# retain env values that were passed to _clone()
937+
repo.git.update_environment(**git.environment())
938+
934939
# adjust remotes - there may be operating systems which use backslashes,
935940
# These might be given as initial paths, but when handling the config file
936941
# that contains the remote from which we were clones, git stops liking it
937942
# as it will escape the backslashes. Hence we undo the escaping just to be
938943
# sure
939-
repo = cls(path, odbt=odbt)
940944
if repo.remotes:
941945
with repo.remotes[0].config_writer as writer:
942946
writer.set_value('url', Git.polish_url(repo.remotes[0].url))

git/test/test_repo.py

+9
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,15 @@ def _assert_empty_repo(self, repo):
201201
pass
202202
# END test repos with working tree
203203

204+
@with_rw_directory
205+
def test_clone_from_keeps_env(self, rw_dir):
206+
original_repo = Repo.init(osp.join(rw_dir, "repo"))
207+
environment = {"entry1": "value", "another_entry": "10"}
208+
209+
cloned = Repo.clone_from(original_repo.git_dir, osp.join(rw_dir, "clone"), env=environment)
210+
211+
assert_equal(environment, cloned.git.environment())
212+
204213
def test_init(self):
205214
prev_cwd = os.getcwd()
206215
os.chdir(tempfile.gettempdir())

0 commit comments

Comments
 (0)