10
10
import subprocess
11
11
import sys
12
12
from tempfile import TemporaryDirectory , TemporaryFile
13
- from unittest import mock
13
+ from unittest import mock , skipUnless
14
14
15
15
from git import Git , refresh , GitCommandError , GitCommandNotFound , Repo , cmd
16
16
from test .lib import TestBase , fixture_path
@@ -105,6 +105,27 @@ def test_it_executes_git_not_from_cwd(self):
105
105
with _chdir (tmpdir ):
106
106
self .assertRegex (self .git .execute (["git" , "version" ]), r"^git version\b" )
107
107
108
+ @skipUnless (is_win , "The regression only affected Windows, and this test logic is OS-specific." )
109
+ def test_it_avoids_upcasing_unrelated_environment_variable_names (self ):
110
+ old_name = "28f425ca_d5d8_4257_b013_8d63166c8158"
111
+ if old_name == old_name .upper ():
112
+ raise RuntimeError ("test bug or strange locale: old_name invariant under upcasing" )
113
+ os .putenv (old_name , "1" ) # It has to be done this lower-level way to set it lower-case.
114
+
115
+ script_lines = [
116
+ "import subprocess, git" ,
117
+
118
+ # Importing git should be enough, but this really makes sure Git.execute is called.
119
+ f"repo = git.Repo({ self .rorepo .working_dir !r} )" ,
120
+ "git.Git(repo.working_dir).execute(['git', 'version'])" ,
121
+
122
+ f"print(subprocess.check_output(['set', { old_name !r} ], shell=True, text=True))" ,
123
+ ]
124
+ cmdline = [sys .executable , "-c" , "\n " .join (script_lines )]
125
+ pair_text = subprocess .check_output (cmdline , shell = False , text = True )
126
+ new_name = pair_text .split ("=" )[0 ]
127
+ self .assertEqual (new_name , old_name )
128
+
108
129
def test_it_accepts_stdin (self ):
109
130
filename = fixture_path ("cat_file_blob" )
110
131
with open (filename , "r" ) as fh :
0 commit comments