feat: add --ref option for diff scope (work, staged, unstaged)#42
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new --ref command-line option to the prep and show commands, allowing users to specify the diff scope as staged, unstaged, or the full working tree. The internal git resolution logic was refactored to support these modes, and the documentation was updated accordingly. A runtime error was identified in the CLI argument parsing where z.enum() is incorrectly used with an object; it should be replaced with z.nativeEnum() to correctly validate the input.
Both `prep` and `show` now accept `--ref <mode>` to control which working-tree changes are included in the diff. Auto-detect behavior is preserved when the flag is omitted.
adad327 to
59aae73
Compare
|
Ready to review this PR? Stage has broken it down into 4 individual chapters for you:
Chapters generated by Stage for commit 42f2a3c on May 14, 2026 2:46am UTC. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 42f2a3c69c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| case WORKING_TREE_REF.STAGED: | ||
| return ["--cached"]; | ||
| case WORKING_TREE_REF.WORK: | ||
| return [mergeBaseSha]; |
There was a problem hiding this comment.
Restrict
work ref to uncommitted changes
The WORK branch currently returns git diff <merge-base> args, and git diff <commit> compares the working tree against that commit (per git-diff docs), so this mode includes committed branch changes since merge-base in addition to staged/unstaged edits. In a branch with local commits, --ref work therefore pulls in already-committed diffs and does not match the documented scope of "staged + unstaged + untracked" changes.
Useful? React with 👍 / 👎.
Summary
Adds a
--ref <mode>flag to bothstagereview prepandstagereview showto control which working-tree changes are included in the diff. The three modes arework(staged + unstaged + untracked),staged(index only), andunstaged(working tree only). When omitted, the existing auto-detect behavior is preserved.Changes
buildWorkingTreeDiffand helpers ingit.tsto unify diff construction for all three ref modes--refoption with Commander.choices()validation to both CLI commandsrefparameter throughprep.tsandshow.tstoresolveScopestage-chaptersskill documentation with the new flagTesting
pnpm typecheck,pnpm lint, andpnpm test(248 tests) all pass