From de139943d8272773b5f19ed824d687b0232b9ba3 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 11 Mar 2023 09:03:03 +0100 Subject: Adding upstream version 0.19.1. Signed-off-by: Daniel Baumann --- gitlint-core/gitlint/shell.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'gitlint-core/gitlint/shell.py') 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) -- cgit v1.2.3