feat: add support for git prepare-commit-msg hook#142
Conversation
Introduced `--install-hook` and `--uninstall-hook` flags to automate
commit message generation via `git commit`. The application now detects
a commit message file argument, allowing it to write generated content
directly to the git buffer instead of triggering an internal commit.
```mermaid
sequenceDiagram
participant User
participant Git
participant Tool
User->>Git: git commit
Git->>Tool: trigger prepare-commit-msg
Tool->>Tool: Generate message
Tool->>Git: Write message to $1
Git->>User: Display editor with message
```
Removed the unused `exePath` parameter from the `InstallHook` function to simplify the API and align with the current implementation, which determines the git directory dynamically.
…t/hooks * 'main' of github.com:rm-hull/git-commit-summary: feat: add `--no-verify` flag to skip git hooks (#141)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Code Review
This pull request adds support for installing and uninstalling the tool as a Git prepare-commit-msg hook, introducing new CLI flags and the ability to write the generated commit message directly to a file. The review feedback highlights several critical issues and improvements: handling user aborts in hook mode by exiting with a non-zero status to prevent Git from proceeding, safely trimming newlines from command outputs to avoid panics and support Windows, using os.Executable() for robust binary path resolution, quoting the executable path in the hook script to handle spaces, and ensuring the hooks directory exists before writing.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Coverage Report for CI Build 28683905270Coverage decreased (-1.9%) to 29.674%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
Add `GIT_COMMIT_SUMMARY_IGNORE_HOOK` environment variable to prevent
infinite loops when `git-commit-summary` triggers a git commit command
that would otherwise invoke the `prepare-commit-msg` hook again.
```mermaid
sequenceDiagram
participant User
participant CLI as git-commit-summary
participant Git
participant Hook as prepare-commit-msg
User->>CLI: Run git commit-summary
CLI->>Git: git commit (env: IGNORE_HOOK=1)
Git->>Hook: Execute hook
Hook->>Hook: Check IGNORE_HOOK
Hook-->>Git: Exit 0 (Ignore)
Git-->>CLI: Commit success
```
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
- Strip both `\n` and `\r` from `gitDir` to support cross-platform path parsing. - Explicitly exit with code 1 when the LLM provider interaction is aborted.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces Git hook integration, allowing git-commit-summary to be installed as a prepare-commit-msg hook. It adds --install-hook and --uninstall-hook flags, supports writing the generated commit message directly to a file, and prevents infinite loops by setting an environment variable when committing. The review feedback highlights several critical issues: argument parsing for the commit message file occurs too late, which breaks abort checks; aborting during hook execution should exit with status code 1 instead of 0 to prevent Git from proceeding; hook installation and uninstallation should safely trim paths and avoid overwriting or deleting third-party hooks; and executable paths on Windows need conversion to forward slashes to prevent shell script escaping issues.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Moves the global `handleError` function into `internal/app/app.go` as a
`HandleError` method on `RunOptions` to centralize and improve
consistency of error reporting across the application.
```mermaid
sequenceDiagram
participant M as Main
participant R as RunOptions
M->>R: HandleError(err)
alt is Aborted
R->>M: Exit (code 1 if file, 0 otherwise)
else is Error
R->>M: Print to Stderr, Exit 1
end
```
Replace hardcoded absolute executable path with `which` lookup in the
`prepare-commit-msg` hook to ensure better portability and resolve
pathing issues across different environments.
```mermaid
sequenceDiagram
participant Hook as prepare-commit-msg
participant Shell
Hook->>Shell: Run which git-commit-summary
Shell-->>Hook: Return executable path
Hook->>Hook: Execute command with --yolo
```
…t/bash-completion * 'main' of github.com:rm-hull/git-commit-summary: feat: add support for git prepare-commit-msg hook (#142)
Introduced
--install-hookand--uninstall-hookflags to automatecommit message generation via
git commit. The application now detectsa commit message file argument, allowing it to write generated content
directly to the git buffer instead of triggering an internal commit.
sequenceDiagram participant User participant Git participant Tool User->>Git: git commit Git->>Tool: trigger prepare-commit-msg Tool->>Tool: Generate message Tool->>Git: Write message to $1 Git->>User: Display editor with message