add a madtea-dev command that splits a working-tree change into ordered atomic commits #629

Open
opened 2026-09-24 18:36:32 +00:00 by hexajon · 0 comments
Owner

What

A large change can mix several concerns, even inside one file, while each concern must land as its own commit that builds and passes on its own. I split the #623 work this way with a Python script, which does not belong in a Go project, so it does not ship. This issue is the Go version, as a madtea-dev subcommand.

Behavior

  • Input: a JSON plan of named steps, in commit order. Each step has rules: path, a regex on the repo-relative path, and an optional hunk, a regex on the hunk's removed and added lines.
  • Every zero-context hunk of git diff -U0 HEAD, and every untracked, not-ignored file (as one hunk), goes to the FIRST step whose rule matches.
  • --report lists the assignment per step and fails when any hunk matches no step. It writes nothing.
  • --stage STEP writes into the index, for each touched file, HEAD's content plus only that step's hunks. The working tree is never modified. The hunks apply to HEAD's content in order, and a hunk whose removed lines do not match HEAD fails the run.
  • After each commit the next --stage diffs against the new HEAD, so line numbers stay exact.

Acceptance

  • Tests cover: two concerns in one file split into two commits; an unassigned hunk failing --report; a mismatched hunk failing --stage; the working tree left untouched.
  • scripts/README.md describes it.
## What A large change can mix several concerns, even inside one file, while each concern must land as its own commit that builds and passes on its own. I split the #623 work this way with a Python script, which does not belong in a Go project, so it does not ship. This issue is the Go version, as a `madtea-dev` subcommand. ## Behavior - Input: a JSON plan of named steps, in commit order. Each step has rules: `path`, a regex on the repo-relative path, and an optional `hunk`, a regex on the hunk's removed and added lines. - Every zero-context hunk of `git diff -U0 HEAD`, and every untracked, not-ignored file (as one hunk), goes to the FIRST step whose rule matches. - `--report` lists the assignment per step and fails when any hunk matches no step. It writes nothing. - `--stage STEP` writes into the index, for each touched file, HEAD's content plus only that step's hunks. The working tree is never modified. The hunks apply to HEAD's content in order, and a hunk whose removed lines do not match HEAD fails the run. - After each commit the next `--stage` diffs against the new HEAD, so line numbers stay exact. ## Acceptance - Tests cover: two concerns in one file split into two commits; an unassigned hunk failing `--report`; a mismatched hunk failing `--stage`; the working tree left untouched. - `scripts/README.md` describes it.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
sixfold-space/madtea#629
No description provided.