Add support for client-side Git hooks and prepare-commit-msg hook#5099
Open
Guilherme1Rocha wants to merge 3 commits intojesseduffield:masterfrom
Open
Add support for client-side Git hooks and prepare-commit-msg hook#5099Guilherme1Rocha wants to merge 3 commits intojesseduffield:masterfrom
Guilherme1Rocha wants to merge 3 commits intojesseduffield:masterfrom
Conversation
8a9c3ee to
ba498d1
Compare
ba498d1 to
d964c2f
Compare
prepare-commit-msg hook
added 2 commits
January 26, 2026 19:15
This change enables lazygit to execute standard client-side Git hooks when they are present in the repository's hooks directory (or a custom directory specified via core.hooksPath). Hooks are only executed if they exist and the command can be run. Missing or non-executable hooks are silently ignored, allowing Git operations to continue normally. If a hook is executable and fails (non-zero exit), the failure is surfaced to the caller. Unit tests cover all scenarios, including: - hooks that run successfully, - hooks that fail, - non-executable hooks (simulated failure), - and missing hooks.
When no commit message is preserved, lazygit attempts 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, lazygit falls back to invoking the prepare-commit-msg hook using a temporary commit message file, mirroring Git’s native behavior. Fixes jesseduffield#4995
d964c2f to
d4f18c5
Compare
Author
|
@stefanhaller , Sorry for the ping. |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 20 |
| Duplication | 7 |
TIP This summary will be updated as you push new changes. Give us feedback
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Support executing client-side Git hooks via
ClientHookCommandsThis PR introduces a new
ClientHookCommandsmodule ingit_commandsto handle execution of Git client hooks in a consistent and Git-faithful manner. Hooks such asprepare-commit-msgare executed automatically when appropriate, and the behavior for missing or non-executable hooks mirrors Git’s defaults.New
ClientHookCommandsmodulecore.hooksPathwhen configured, falling back to the repository’s.git/hooksdirectory.Integration with commit flow
prepare-commit-msghook is invoked when no commit prefix is generated from user configuration.Fixes #4995
Please check if the PR fulfills these requirements
go generate ./...)