Skip to content

feat(git): improve generated commit hook usability - #246

Merged
dpc merged 1 commit into
masterfrom
dpc/jj-kzvruqxxloqx
Jul 24, 2026
Merged

feat(git): improve generated commit hook usability#246
dpc merged 1 commit into
masterfrom
dpc/jj-kzvruqxxloqx

Conversation

@dpc

@dpc dpc commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Posted by Tau

Summary

Improve generated commit-hook failure output: preserve failed messages with safe original-command retry guidance, provide a one-environment hook bypass, and compact slow-check warnings without changing check output or status behavior.

Details

  • On a commit-msg failure with .git/COMMIT_EDITMSG, tell users to rerun their original git commit command while replacing message options with -eF .git/COMMIT_EDITMSG. This retains options such as -a and --amend; pre-commit failures do not show message recovery advice.
  • Skip Flakebox-generated pre-commit and commit-msg checks only when FLAKEBOX_SKIP_GIT_HOOKS=1. Unset or other values run checks normally. Git’s --no-verify remains an alternative.
  • Stream generated-hook stderr through a bounded marker formatter so slow warnings have no needless surrounding blank lines while unterminated and NUL output remains complete.
  • Add behavioral coverage for hook placement/failures, option-preserving recovery, both bypassed hooks, warning boundaries, signals/status, output closure, and background descendants.

Reviewers can exercise the behavior with the gitHooks flake check.

### Summary

Make failed generated commit-message checks explain how to reuse Git’s preserved message without misleading users when pre-commit checks fail earlier. Add an exact-value environment bypass for both generated commit hooks and keep generated slow-check warnings compact. Document the bypass and standalone timer fallback, and cover recovery placement, option-preserving retries, bypass semantics, failure behavior, and byte-exact warning formatting.

### Details

Generated commit-msg hooks now report that `.git/COMMIT_EDITMSG` is saved only after a failed check when Git invoked the hook with that exact populated path in a normal checkout. They tell users to rerun their original `git commit` command, replacing message options with `-eF .git/COMMIT_EDITMSG`, which preserves operations such as `-a` and `--amend`. Generated pre-commit hooks never print this recovery advice.

Setting `FLAKEBOX_SKIP_GIT_HOOKS=1` bypasses both generated paths; unset and all other values run normally. Git’s existing `--no-verify` remains documented as an alternative. The variable lives only in Flakebox-generated scripts and does not alter unrelated hooks.

The generated timed runner marks warning records and streams GNU Parallel stderr through a bounded formatter. It inserts a separator only after unterminated output, removes leading and consecutive blank warning lines, preserves NUL and ordinary bytes, propagates output closure, retains aggregate check status, and closes its formatter descriptor in workers. Standalone internal timer use conservatively retains a leading newline because arbitrary inherited stderr cannot be inspected portably. Regenerate Flakebox’s checked-in hook artifacts and root identity.

### Reviews

An independent reliability review initially found unsafe plain-commit retry advice, stderr-proxy hangs and EPIPE/status changes, delayed unbounded buffering, NUL mishandling, a leaked formatter descriptor, and non-portable direct-stderr inspection. The implementation replaced the advice with option-preserving original-command guidance, removed proxy/temp-file designs, added bounded streaming marker formatting, closed the worker descriptor, and narrowed standalone timer behavior with dpc’s approval. Three follow-up reviews verified each fix; the final review passed with no findings.

### Validation

- `nix develop -c treefmt`
- focused `gitHooks` Nix check
- `nix develop -c selfci check`
- `nix develop -c selfci check --candidate kzvruqxx`
@dpc
dpc marked this pull request as ready for review July 24, 2026 22:21
@dpc
dpc merged commit d5a6806 into master Jul 24, 2026
4 checks passed
@dpc
dpc deleted the dpc/jj-kzvruqxxloqx branch July 24, 2026 22:21
dpc added a commit that referenced this pull request Jul 30, 2026
feat(git): improve generated commit hook usability
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.

1 participant