diff options
Diffstat (limited to '')
-rw-r--r-- | gitlint-core/gitlint/shell.py | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/gitlint-core/gitlint/shell.py b/gitlint-core/gitlint/shell.py index c378c1c..fddece0 100644 --- a/gitlint-core/gitlint/shell.py +++ b/gitlint-core/gitlint/shell.py @@ -5,7 +5,8 @@ capabilities wrt dealing with more edge-case environments on *nix systems that a """ import subprocess -from gitlint.utils import USE_SH_LIB, DEFAULT_ENCODING + +from gitlint.utils import TERMINAL_ENCODING, USE_SH_LIB def shell(cmd): @@ -15,17 +16,17 @@ def shell(cmd): if USE_SH_LIB: - from sh import git # pylint: disable=unused-import,import-error - # import exceptions separately, this makes it a little easier to mock them out in the unit tests - from sh import CommandNotFound, ErrorReturnCode # pylint: disable=import-error + from sh import ( + CommandNotFound, + ErrorReturnCode, + git, + ) else: class CommandNotFound(Exception): """Exception indicating a command was not found during execution""" - pass - class ShResult: """Result wrapper class. We use this to more easily migrate from using https://amoffat.github.io/sh/ to using the builtin subprocess module""" @@ -42,14 +43,12 @@ else: class ErrorReturnCode(ShResult, Exception): """ShResult subclass for unexpected results (acts as an exception).""" - pass - def git(*command_parts, **kwargs): """Git shell wrapper. Implemented as separate function here, so we can do a 'sh' style imports: `from shell import git` """ - args = ["git"] + list(command_parts) + args = ["git", *list(command_parts)] return _exec(*args, **kwargs) def _exec(*args, **kwargs): @@ -65,7 +64,7 @@ else: raise CommandNotFound from e exit_code = p.returncode - stdout = result[0].decode(DEFAULT_ENCODING) + stdout = result[0].decode(TERMINAL_ENCODING) stderr = result[1] # 'sh' does not decode the stderr bytes to unicode full_cmd = "" if args is None else " ".join(args) |