Skip to content

Commit 53373c8

Browse files
committed
Keeping env values passed to clone_from
1 parent ddb828e commit 53373c8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

‎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)