Skip to content

Fix Windows environment variable upcasing bug #1650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 7, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add test for Windows env var upcasing regression
  • Loading branch information
EliahKagan committed Sep 7, 2023
commit d88372a11ac145d92013dcc64b7d21a5a6ad3a91
23 changes: 22 additions & 1 deletion test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import subprocess
import sys
from tempfile import TemporaryDirectory, TemporaryFile
from unittest import mock
from unittest import mock, skipUnless

from git import Git, refresh, GitCommandError, GitCommandNotFound, Repo, cmd
from test.lib import TestBase, fixture_path
Expand Down Expand Up @@ -105,6 +105,27 @@ def test_it_executes_git_not_from_cwd(self):
with _chdir(tmpdir):
self.assertRegex(self.git.execute(["git", "version"]), r"^git version\b")

@skipUnless(is_win, "The regression only affected Windows, and this test logic is OS-specific.")
def test_it_avoids_upcasing_unrelated_environment_variable_names(self):
old_name = "28f425ca_d5d8_4257_b013_8d63166c8158"
if old_name == old_name.upper():
raise RuntimeError("test bug or strange locale: old_name invariant under upcasing")
os.putenv(old_name, "1") # It has to be done this lower-level way to set it lower-case.

script_lines = [
"import subprocess, git",

# Importing git should be enough, but this really makes sure Git.execute is called.
f"repo = git.Repo({self.rorepo.working_dir!r})",
"git.Git(repo.working_dir).execute(['git', 'version'])",

f"print(subprocess.check_output(['set', {old_name!r}], shell=True, text=True))",
]
cmdline = [sys.executable, "-c", "\n".join(script_lines)]
pair_text = subprocess.check_output(cmdline, shell=False, text=True)
new_name = pair_text.split("=")[0]
self.assertEqual(new_name, old_name)

def test_it_accepts_stdin(self):
filename = fixture_path("cat_file_blob")
with open(filename, "r") as fh:
Expand Down