Skip to content

Conversation

@Guilherme1Rocha
Copy link

@Guilherme1Rocha Guilherme1Rocha commented Dec 9, 2025

PR Description

Add ClientHookCommands to run Git client hook executables

This PR introduces a new ClientHookCommands module in git_commands to handle running Git client hooks in a structured and consistent way. It ensures that hooks such as prepare-commit-msg are executed correctly when appropriate, and respects Git’s native behavior regarding missing or non-executable hooks.

Key changes

  • New ClientHookCommands

    • Provides methods to run client hook executables (pre-commit, prepare-commit-msg, commit-msg, etc.).
    • Abstracts command execution and error handling for Git hooks.
  • Integration with HandleCommitPress

    • If no commit prefix rules are defined, the prepare-commit-msg hook is executed automatically.
    • Fallback behavior matches Git: missing or non-executable hooks are treated as no-ops.

Fixes #4995

Please check if the PR fulfills these requirements

  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

Add support for executing standard client-side Git hooks from
lazygit. Hooks are discovered in the repository's .git/hooks
directory and executed only if they exist and are executable,
matching Git's default behavior.

Errors from missing or non-executable hooks are intentionally
ignored so normal Git operations can proceed, while failures
from executable hooks are surfaced to the caller.

This change also introduces tests covering successful execution,
hook failures, non-executable hooks, and missing hooks to ensure
behavior remains consistent with Git expectations.
When no commit message is preserved, attempt to generate a commit
prefix before opening the commit flow. User-configured commit
prefix patterns are evaluated first and applied based on the
current branch name.

If no configured prefix matches, fall back to invoking the
prepare-commit-msg hook using a temporary commit message file,
mirroring Git’s native behavior.
@Guilherme1Rocha Guilherme1Rocha force-pushed the feature/prepare-commit-msg-git-hook-support branch from 8a9c3ee to ba498d1 Compare December 25, 2025 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support prepare-commit-msg Git hook

1 participant