Address issue #1130: make pip ignore GIT_DIR and GIT_WORK_TREE.

This commit is contained in:
Chris Jerdonek 2017-08-11 03:25:16 -07:00
parent 035a2a720b
commit 3498b19a8b
4 changed files with 19 additions and 2 deletions

2
news/1130.bugfix Normal file
View File

@ -0,0 +1,2 @@
Allow pip to work if the ``GIT_DIR`` and ``GIT_WORK_TREE`` environment
variables are set.

View File

@ -627,7 +627,14 @@ def unpack_file(filename, location, content_type, link):
def call_subprocess(cmd, show_stdout=True, cwd=None,
on_returncode='raise',
command_desc=None,
extra_environ=None, spinner=None):
extra_environ=None, unset_environ=None, spinner=None):
"""
Args:
unset_environ: an iterable of environment variable names to unset
prior to calling subprocess.Popen().
"""
if unset_environ is None:
unset_environ = []
# This function's handling of subprocess output is confusing and I
# previously broke it terribly, so as penance I will write a long comment
# explaining things.
@ -664,6 +671,8 @@ def call_subprocess(cmd, show_stdout=True, cwd=None,
env = os.environ.copy()
if extra_environ:
env.update(extra_environ)
for name in unset_environ:
env.pop(name, None)
try:
proc = subprocess.Popen(
cmd, stderr=subprocess.STDOUT, stdin=None, stdout=stdout,

View File

@ -166,6 +166,8 @@ class VersionControl(object):
dirname = ''
# List of supported schemes for this Version Control
schemes = () # type: Tuple[str, ...]
# Iterable of environment variable names to pass to call_subprocess().
unset_environ = ()
default_arg_rev = None # type: Optional[str]
def __init__(self, url=None, *args, **kwargs):
@ -422,7 +424,8 @@ class VersionControl(object):
return call_subprocess(cmd, show_stdout, cwd,
on_returncode,
command_desc, extra_environ,
spinner)
unset_environ=self.unset_environ,
spinner=spinner)
except OSError as e:
# errno.ENOENT = no such file or directory
# In other words, the VCS executable isn't available

View File

@ -27,6 +27,9 @@ class Git(VersionControl):
schemes = (
'git', 'git+http', 'git+https', 'git+ssh', 'git+git', 'git+file',
)
# Prevent the user's environment variables from interfering with pip:
# https://github.com/pypa/pip/issues/1130
unset_environ = ('GIT_DIR', 'GIT_WORK_TREE')
default_arg_rev = 'origin/HEAD'
def __init__(self, url=None, *args, **kwargs):