PrimeIntellect/SWE-rebench-V2 huggingface dataset:
Repository: gitpython-developers/GitPython (python)

Issue:
Environment values passed to Repo.clone_from() are not kept in the resulting repo
    r = Repo.clone_from("git@github.com:bpiotr/whatever_repo.git", "/tmp/repo", env={"key": "value"})
    r.git.environment()
    {}

This is not what I expected when I called `Repo.clone_from` and documentation does not elaborate on the transient nature of the `env` here so IMHO this is a bug. 

BTW it costed me quite a while to figure out that `clone_from` actually uses `env` but any subsequent operations on the result needs it to have it set again.

Pull request:
Retaining env on clone_from
fixes #676

Patch:
diff --git a/AUTHORS b/AUTHORS
index 2b67d6cb..98167ea7 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -22,5 +22,6 @@ Contributors are:
 -Anson Mansfield <anson.mansfield _at_ gmail.com>
 -Ken Odegard <ken.odegard _at_ gmail.com>
 -Alexis Horgix Chotard
+-Piotr Babij <piotr.babij _at_ gmail.com>
 
 Portions derived from other open source works and are clearly marked.
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))


Test patch:
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())