From 929c95833d2214631a8493c4822a78d88766f44d Mon Sep 17 00:00:00 2001 From: Chris Jerdonek Date: Thu, 20 Dec 2018 17:36:28 -0800 Subject: [PATCH] Address review comments. --- src/pip/_internal/utils/misc.py | 12 ++++++------ src/pip/_internal/vcs/__init__.py | 4 ++-- src/pip/_internal/vcs/git.py | 8 +++++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/pip/_internal/utils/misc.py b/src/pip/_internal/utils/misc.py index fdd7de908a9..bb6e515173a 100644 --- a/src/pip/_internal/utils/misc.py +++ b/src/pip/_internal/utils/misc.py @@ -653,7 +653,7 @@ def call_subprocess( show_stdout=True, # type: bool cwd=None, # type: Optional[str] on_returncode='raise', # type: str - returncodes=None, # type: Optional[Iterable[int]] + extra_ok_returncodes=None, # type: Optional[Iterable[int]] command_desc=None, # type: Optional[str] extra_environ=None, # type: Optional[Mapping[str, Any]] unset_environ=None, # type: Optional[Iterable[str]] @@ -662,13 +662,13 @@ def call_subprocess( # type: (...) -> Optional[Text] """ Args: - returncodes: an iterable of integer return codes that are acceptable, - in addition to 0. Defaults to None, which means []. + extra_ok_returncodes: an iterable of integer return codes that are + acceptable, in addition to 0. Defaults to None, which means []. unset_environ: an iterable of environment variable names to unset prior to calling subprocess.Popen(). """ - if returncodes is None: - returncodes = [] + if extra_ok_returncodes is None: + extra_ok_returncodes = [] if unset_environ is None: unset_environ = [] # This function's handling of subprocess output is confusing and I @@ -745,7 +745,7 @@ def call_subprocess( spinner.finish("error") else: spinner.finish("done") - if proc.returncode and proc.returncode not in returncodes: + if proc.returncode and proc.returncode not in extra_ok_returncodes: if on_returncode == 'raise': if (logger.getEffectiveLevel() > std_logging.DEBUG and not show_stdout): diff --git a/src/pip/_internal/vcs/__init__.py b/src/pip/_internal/vcs/__init__.py index a432c3868e8..c9353f0887b 100644 --- a/src/pip/_internal/vcs/__init__.py +++ b/src/pip/_internal/vcs/__init__.py @@ -467,7 +467,7 @@ def run_command( show_stdout=True, # type: bool cwd=None, # type: Optional[str] on_returncode='raise', # type: str - returncodes=None, # type: Optional[Iterable[int]] + extra_ok_returncodes=None, # type: Optional[Iterable[int]] command_desc=None, # type: Optional[str] extra_environ=None, # type: Optional[Mapping[str, Any]] spinner=None # type: Optional[SpinnerInterface] @@ -482,7 +482,7 @@ def run_command( try: return call_subprocess(cmd, show_stdout, cwd, on_returncode=on_returncode, - returncodes=returncodes, + extra_ok_returncodes=extra_ok_returncodes, command_desc=command_desc, extra_environ=extra_environ, unset_environ=self.unset_environ, diff --git a/src/pip/_internal/vcs/git.py b/src/pip/_internal/vcs/git.py index e32bba8c1c4..cae01610f6a 100644 --- a/src/pip/_internal/vcs/git.py +++ b/src/pip/_internal/vcs/git.py @@ -84,11 +84,13 @@ def get_current_branch(self, location): Return the current branch, or None if HEAD isn't at a branch (e.g. detached HEAD). """ - # The -q causes the command to exit with status code 1 instead of - # 128 if "HEAD" is not a symbolic ref but a detached HEAD. + # git-symbolic-ref exits with empty stdout if "HEAD" is a detached + # HEAD rather than a symbolic ref. In addition, the -q causes the + # command to exit with status code 1 instead of 128 in this case + # and to suppress the message to stderr. args = ['symbolic-ref', '-q', 'HEAD'] output = self.run_command( - args, returncodes=(1, ), show_stdout=False, cwd=location, + args, extra_ok_returncodes=(1, ), show_stdout=False, cwd=location, ) ref = output.strip()