From 284cdb60b01599c387ff57b9adb70ced9a2a2fe9 Mon Sep 17 00:00:00 2001 From: Bas van der Vlies Date: Tue, 6 Aug 2024 13:37:56 +0200 Subject: [PATCH 1/2] git promise type must just continue if we have unicode error closes https://github.com/cfengine/modules/issues/99 --- promise-types/git/git.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/promise-types/git/git.py b/promise-types/git/git.py index 0a6fecc..1ccab38 100644 --- a/promise-types/git/git.py +++ b/promise-types/git/git.py @@ -236,16 +236,21 @@ def evaluate_promise(self, promiser: str, attributes: Dict, metadata: Dict): def _git(self, model: object, args: List[str], cwd: Optional[str] = None) -> str: self.log_verbose("Run: {cmd}".format(cmd=" ".join(args))) - output = ( - subprocess.check_output( - args, - env=self._git_envvars(model), - cwd=cwd, - stderr=subprocess.PIPE, + try: + output = ( + subprocess.check_output( + args, + env=self._git_envvars(model), + cwd=cwd, + stderr=subprocess.PIPE, + ) + .strip() + .decode("utf-8") ) - .strip() - .decode("utf-8") - ) + except UnicodeDecodeError: + output = "Could not decode output, just continue" + pass + output != "" and self.log_verbose(output) return output From eb8af73228a70374efc7755632dd8ef17ea65675 Mon Sep 17 00:00:00 2001 From: Bas van der Vlies Date: Mon, 12 Aug 2024 17:54:19 +0200 Subject: [PATCH 2/2] use `-shorstat` option this will prevent unidcode errors in the `diff` output and will detect changes --- promise-types/git/git.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/promise-types/git/git.py b/promise-types/git/git.py index 1ccab38..0766b08 100644 --- a/promise-types/git/git.py +++ b/promise-types/git/git.py @@ -192,6 +192,7 @@ def evaluate_promise(self, promiser: str, attributes: Dict, metadata: Dict): [ model.executable, "diff", + "--shortstat", "..{remote}/{version}".format( remote=model.remote, version=model.version ), @@ -236,21 +237,16 @@ def evaluate_promise(self, promiser: str, attributes: Dict, metadata: Dict): def _git(self, model: object, args: List[str], cwd: Optional[str] = None) -> str: self.log_verbose("Run: {cmd}".format(cmd=" ".join(args))) - try: - output = ( - subprocess.check_output( - args, - env=self._git_envvars(model), - cwd=cwd, - stderr=subprocess.PIPE, - ) - .strip() - .decode("utf-8") + output = ( + subprocess.check_output( + args, + env=self._git_envvars(model), + cwd=cwd, + stderr=subprocess.PIPE, ) - except UnicodeDecodeError: - output = "Could not decode output, just continue" - pass - + .strip() + .decode("utf-8") + ) output != "" and self.log_verbose(output) return output