Skip to content

Commit 8df6b87

Browse files
author
Darragh Bailey
committed
Copy environment for subprocess execution
Git utilizes multiple environment variables to control various behaviours. Make sure to set LC_MESSAGES on a copy of the environment instead of discarding any variables that may be set by the user or default shell environment such as EDITOR. Add test to assert that when overriding GIT_EDITOR via os.environ that the modified value will be picked up by and git commands called.
1 parent 2af9892 commit 8df6b87

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Diff for: git/cmd.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,10 @@ def execute(self, command,
341341
cwd = self._working_dir
342342

343343
# Start the process
344+
env = os.environ.copy()
345+
env["LC_MESSAGES"] = "C"
344346
proc = Popen(command,
345-
env={"LC_MESSAGES": "C"},
347+
env=env,
346348
cwd=cwd,
347349
stdin=istream,
348350
stderr=PIPE,

Diff for: git/test/test_git.py

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66

77
import os
8+
import mock
89
from git.test.lib import (TestBase,
910
patch,
1011
raises,
@@ -128,3 +129,8 @@ def test_single_char_git_options_are_passed_to_git(self):
128129

129130
def test_change_to_transform_kwargs_does_not_break_command_options(self):
130131
self.git.log(n=1)
132+
133+
def test_env_vars_passed_to_git(self):
134+
editor = 'non_existant_editor'
135+
with mock.patch.dict('os.environ', {'GIT_EDITOR': editor}):
136+
assert self.git.var("GIT_EDITOR") == editor

0 commit comments

Comments
 (0)