Skip to content

Commit

Permalink
17265 FIX Git: Support long commit messages
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ottermata committed Sep 9, 2024
1 parent ac7e8ed commit b7de2a8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
16 changes: 16 additions & 0 deletions .werks/17265.md
Original file line number Diff line number Diff line change
@@ -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.
20 changes: 13 additions & 7 deletions cmk/gui/watolib/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 <tt>%s</tt>:<br><br>%s")
% (subprocess.list2cmdline(command), e)
_("Error executing GIT command <tt>%s</tt>:<br><br>%s") % (debug_command, e)
) from e

if completed_process.returncode:
raise MKGeneralException(
_("Error executing GIT command <tt>%s</tt>:<br><br>%s")
% (subprocess.list2cmdline(command), completed_process.stdout.replace("\n", "<br>\n"))
% (debug_command, completed_process.stdout.replace("\n", "<br>\n"))
)


Expand Down

0 comments on commit b7de2a8

Please sign in to comment.