From d40619ddbe64c98d150d8648a522ec8a4d2727ea Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" Date: Wed, 2 Apr 2025 18:53:10 +0000 Subject: [PATCH] ci: Do swallow gitlint warning, when not found or unexpectedly failed Gitlint returns error code 253 for a "wrong invocation" i.e. missing filename for the commit message. That one signals a successful existing install. Return a warning when either Git is not found (so no hooks will run) or Gitlint failed its hook installation. Part-of: --- meson.build | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 6526550944..5cb664daf1 100644 --- a/meson.build +++ b/meson.build @@ -35,9 +35,16 @@ endif gitlint_req = '>= 0.18' gitlint = find_program('gitlint', version: gitlint_req, required: false) if gitlint.found() - gitlint_status = run_command(gitlint, 'install-hook', check: false) - if gitlint_status.returncode() != 0 - warning(gitlint_status.stderr().strip()) + git = find_program('git', required: false) + if git.found() and fsmod.is_dir(meson.current_source_dir() / '.git') + gitlint_status = run_command(git, 'hook', 'run', 'commit-msg', check: false) + # exit code 253 means "wrong invocation" in Gitlint + if gitlint_status.returncode() != 253 + gitlint_status = run_command(gitlint, 'install-hook', check: false) + if gitlint_status.returncode() != 0 + warning(gitlint_status.stderr().strip()) + endif + endif endif else warning('gitlint not found or too old, please install it with your package manager or `python3 -m pip install gitlint` to enable the commit message hook')