From b7de2a8b0bd42657ba910fb439cb9afc54f27ad4 Mon Sep 17 00:00:00 2001 From: Christopher Krause Date: Mon, 2 Sep 2024 12:57:17 +0200 Subject: [PATCH] 17265 FIX Git: Support long commit messages When the Git integration was enabled, creating thousands of hosts could result in a crash. This was caused by a limit of the command line. This werk improves the Git integration to support longer messages. Change-Id: I03a5737a16778f34e82f9dc2ee79dc739db25304 JIRA-Ref: SUP-19722 --- .werks/17265.md | 16 ++++++++++++++++ cmk/gui/watolib/git.py | 20 +++++++++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 .werks/17265.md diff --git a/.werks/17265.md b/.werks/17265.md new file mode 100644 index 00000000000..e25b57f7eec --- /dev/null +++ b/.werks/17265.md @@ -0,0 +1,16 @@ +[//]: # (werk v2) +# Git: Support long commit messages + +key | value +---------- | --- +date | 2024-09-02T10:27:11+00:00 +version | 2.4.0b1 +class | fix +edition | cre +component | wato +level | 1 +compatible | yes + +When the Git integration was enabled, creating thousands of hosts could result +in a crash. This was caused by a limit of the command line. +This werk improves the Git integration to support longer messages. diff --git a/cmk/gui/watolib/git.py b/cmk/gui/watolib/git.py index 1cbb555a8f8..00c63135195 100644 --- a/cmk/gui/watolib/git.py +++ b/cmk/gui/watolib/git.py @@ -68,7 +68,7 @@ def do_git_commit() -> None: if not message: message = _("Unknown configuration change") - _git_command(["commit", "--author", author, "-m", message]) + _git_command(["commit", "--author", author, "-F", "-"], stdin=message) def _git_add_files() -> None: @@ -79,32 +79,38 @@ def _git_add_files() -> None: _git_command(["add", "--all", ".gitignore"] + rel_paths) -def _git_command(args: list[str]) -> None: +def _git_command(args: list[str], stdin: str | None = None) -> None: command = ["git"] + args + debug_command = subprocess.list2cmdline(command) + if stdin: + if (len_stdin := len(stdin)) > 50: + debug_command += f" < {stdin[:45]}[...] ({len_stdin} chars)" + else: + debug_command += f" < {stdin}" logger.debug( "GIT: Execute in %s: %s", cmk.utils.paths.default_config_dir, - subprocess.list2cmdline(command), + debug_command, ) try: completed_process = subprocess.run( command, cwd=cmk.utils.paths.default_config_dir, + input=stdin, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf-8", check=False, ) - except FileNotFoundError as e: + except (FileNotFoundError, UnicodeEncodeError) as e: raise MKGeneralException( - _("Error executing GIT command %s:

%s") - % (subprocess.list2cmdline(command), e) + _("Error executing GIT command %s:

%s") % (debug_command, e) ) from e if completed_process.returncode: raise MKGeneralException( _("Error executing GIT command %s:

%s") - % (subprocess.list2cmdline(command), completed_process.stdout.replace("\n", "
\n")) + % (debug_command, completed_process.stdout.replace("\n", "
\n")) )