Skip to content

feat: add support for git prepare-commit-msg hook#142

Merged
rm-hull merged 18 commits into
mainfrom
feat/hooks
Jul 3, 2026
Merged

feat: add support for git prepare-commit-msg hook#142
rm-hull merged 18 commits into
mainfrom
feat/hooks

Conversation

@rm-hull

@rm-hull rm-hull commented Jul 2, 2026

Copy link
Copy Markdown
Owner

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.

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
Loading

rm-hull added 3 commits July 2, 2026 23:46
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)
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor
TestsPassed ✅SkippedFailed
JUnit Test Report63 ran63 passed0 skipped0 failed
TestResult
JUnit Test Report
com/rm-hull/git-commit-summary/internal/config.TestLoad/Defaults✅ passed
com/rm-hull/git-commit-summary/internal/config.TestLoad/WithEnvironmentVariables✅ passed
com/rm-hull/git-commit-summary/internal/config.TestLoad✅ passed
com/rm-hull/git-commit-summary/internal/config.Test_updateProperties/handle_empty_quoted_strings✅ passed
com/rm-hull/git-commit-summary/internal/config.Test_updateProperties/empty_file,_add_new_properties✅ passed
com/rm-hull/git-commit-summary/internal/config.Test_updateProperties/existing_file,_update_properties✅ passed
com/rm-hull/git-commit-summary/internal/config.Test_updateProperties/doesnt_overwrite_values_if_new_value_is_the_same✅ passed
com/rm-hull/git-commit-summary/internal/config.Test_updateProperties/existing_file,_add_new_and_update_existing✅ passed
com/rm-hull/git-commit-summary/internal/config.Test_updateProperties/preserve_comments_and_other_lines✅ passed
com/rm-hull/git-commit-summary/internal/config.Test_updateProperties/handle_mixed_quoting_styles✅ passed
com/rm-hull/git-commit-summary/internal/config.Test_updateProperties/empty_props,_no_changes✅ passed
com/rm-hull/git-commit-summary/internal/config.Test_updateProperties/properties_with_special_characters✅ passed
com/rm-hull/git-commit-summary/internal/config.Test_updateProperties✅ passed
com/rm-hull/git-commit-summary/internal/git.TestClient_prepareCommitMessage/Single_line_message_with_skipCI✅ passed
com/rm-hull/git-commit-summary/internal/git.TestClient_prepareCommitMessage/Multi-line_message_with_skipCI✅ passed
com/rm-hull/git-commit-summary/internal/git.TestClient_prepareCommitMessage/Single_line_message_without_skipCI✅ passed
com/rm-hull/git-commit-summary/internal/git.TestClient_prepareCommitMessage/Multi-line_message_without_skipCI✅ passed
com/rm-hull/git-commit-summary/internal/git.TestClient_prepareCommitMessage/Empty_message_with_skipCI✅ passed
com/rm-hull/git-commit-summary/internal/git.TestClient_prepareCommitMessage✅ passed
com/rm-hull/git-commit-summary/internal/llm_provider.TestNewProvider/GoogleProvider✅ passed
com/rm-hull/git-commit-summary/internal/llm_provider.TestNewProvider/OpenAIProvider✅ passed
com/rm-hull/git-commit-summary/internal/llm_provider.TestNewProvider/UnknownProvider✅ passed
com/rm-hull/git-commit-summary/internal/llm_provider.TestNewProvider✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestHistory/NewHistory✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestHistory/Add_and_Value✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestHistory/Undo✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestHistory/Redo✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestHistory/Undo_at_beginning✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestHistory/Redo_at_end✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestHistory/Add_truncates_future_history✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestHistory/Multiple_Undos_and_Redos✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestHistory✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/tea.KeyMsg_-_CtrlC_in_showSpinner_state✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/tea.KeyMsg_-_CtrlC_in_other_states✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/gitCheckMsg_-_empty_(no_staged_changes)✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/gitCheckMsg_-_non-empty_(staged_changes)✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/gitDiffMsg_with_hint✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/llmResultMsg_-_with_user_message✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/llmResultMsg_-_without_user_message✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/commitMsg✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/regenerateMsg_-_initializes_promptView_with_current_hint✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/userResponseMsg_-_updates_m.hint✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/cancelRegenPromptMsg_-_re-enables_help_text✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/errMsg✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/abortMsg✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/spinner.Update_for_showSpinner_state✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/commitView.Update_for_showCommitView_state✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/promptView.Update_for_showRegeneratePrompt_state✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/llmResultMsg_-_YOLO_mode✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/llmResultMsg_-_YOLO_mode_-_empty_summary✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/gitDiffMsg_-_includes_recent_commits_in_prompt✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestTrimTrailingSpaces/no_trailing_spaces✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestTrimTrailingSpaces/trailing_spaces_on_some_lines✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestTrimTrailingSpaces/tabs_and_carriage_returns✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestTrimTrailingSpaces/empty_string✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestTrimTrailingSpaces/single_line_with_space✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestTrimTrailingSpaces✅ passed
com/rm-hull/git-commit-summary/internal/version.TestCheckLatestReturnsLatestWhenNewer✅ passed
com/rm-hull/git-commit-summary/internal/version.TestCheckLatestReturnsEmptyWhenUpToDate✅ passed
com/rm-hull/git-commit-summary/internal/version.TestCheckLatestReturnsEmptyForDevel✅ passed
com/rm-hull/git-commit-summary/internal/version.TestCheckLatestWithRevSuffix✅ passed
com/rm-hull/git-commit-summary/internal/version.TestCheckLatestWithRevSuffixAndUpToDate✅ passed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread main.go Outdated
Comment thread internal/setup/hooks.go Outdated
Comment thread internal/setup/hooks.go Outdated
Comment thread internal/setup/hooks.go Outdated
Comment thread internal/setup/hooks.go
Comment thread internal/setup/hooks.go Outdated
@coveralls

coveralls commented Jul 2, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 28683905270

Coverage decreased (-1.9%) to 29.674%

Details

  • Coverage decreased (-1.9%) from the base build.
  • Patch coverage: 116 uncovered changes across 4 files (0 of 116 lines covered, 0.0%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
internal/setup/hooks.go 49 0 0.0%
main.go 37 0 0.0%
internal/app/app.go 29 0 0.0%
internal/git/client.go 1 0 0.0%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 1412
Covered Lines: 419
Line Coverage: 29.67%
Coverage Strength: 0.32 hits per line

💛 - Coveralls

rm-hull and others added 6 commits July 3, 2026 18:10
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.
@rm-hull

rm-hull commented Jul 3, 2026

Copy link
Copy Markdown
Owner Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread main.go
Comment thread main.go Outdated
Comment thread internal/setup/hooks.go Outdated
Comment thread internal/setup/hooks.go Outdated
Comment thread internal/setup/hooks.go
Comment thread internal/setup/hooks.go Outdated
rm-hull and others added 9 commits July 3, 2026 19:52
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
```
@rm-hull rm-hull merged commit f93dddb into main Jul 3, 2026
3 checks passed
@rm-hull rm-hull deleted the feat/hooks branch July 3, 2026 21:32
rm-hull added a commit that referenced this pull request Jul 3, 2026
…t/bash-completion

* 'main' of github.com:rm-hull/git-commit-summary:
  feat: add support for git prepare-commit-msg hook (#142)
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.

2 participants