Skip to content

Optional per-commit validation hook (--verify) for staged snapshot #58

Description

@wkentaro

This was generated by AI.

Problem

git-hunk's whole purpose is producing a clean series of focused commits where each commit is independently valid. But nothing enforces that invariant — an agent can stage a partial hunk that leaves the file unparseable (e.g. a selection that drops a closing brace) and only find out later.

Proposal

Add an optional validation command that runs against the staged-tree snapshot and refuses the stage (non-zero exit) on failure:

git-hunk stage 66279ce -l ^115-119 --verify 'python -m py_compile path/to/file.py'

Behavior:

  • Materialize the would-be-staged content (the same snapshot preview would emit), run the --verify command against it, and only commit the stage to the index if the command exits 0.
  • On failure, leave the index untouched and report the command's output.

This bakes the "each commit builds" discipline into the tool instead of relying on the agent to remember to check.

Notes

  • Depends conceptually on materializing the staged file state (see the preview issue); could share that machinery.
  • Could later be promoted to a configurable default (e.g. a repo-level verify command) but a per-invocation flag is the minimal version.
  • One of a set of agent-usability ideas from the same session.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageissue: Maintainer needs to evaluate this issuetype: featureissue: Requesting a new capability or improvement

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions