Skip to content

feat: add --ref option for diff scope (work, staged, unstaged)#42

Merged
dastratakos merged 2 commits into
mainfrom
dastratakos/toggle-untracked-changes
May 14, 2026
Merged

feat: add --ref option for diff scope (work, staged, unstaged)#42
dastratakos merged 2 commits into
mainfrom
dastratakos/toggle-untracked-changes

Conversation

@dastratakos
Copy link
Copy Markdown
Contributor

@dastratakos dastratakos commented May 7, 2026

Summary

Adds a --ref <mode> flag to both stagereview prep and stagereview show to control which working-tree changes are included in the diff. The three modes are work (staged + unstaged + untracked), staged (index only), and unstaged (working tree only). When omitted, the existing auto-detect behavior is preserved.

Changes

  • Extracted buildWorkingTreeDiff and helpers in git.ts to unify diff construction for all three ref modes
  • Added --ref option with Commander .choices() validation to both CLI commands
  • Threaded the ref parameter through prep.ts and show.ts to resolveScope
  • Updated stage-chapters skill documentation with the new flag

Testing

  • pnpm typecheck, pnpm lint, and pnpm test (248 tests) all pass

Open in Stage

Copy link
Copy Markdown

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

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 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.

Comment thread packages/cli/src/index.ts
Comment thread packages/cli/src/index.ts
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.
@dastratakos dastratakos force-pushed the dastratakos/toggle-untracked-changes branch from adad327 to 59aae73 Compare May 14, 2026 02:01
@stage-review
Copy link
Copy Markdown

stage-review Bot commented May 14, 2026

Ready to review this PR? Stage has broken it down into 4 individual chapters for you:

Title
1 Refactor git diff logic to support modes
2 Thread ref parameter through prep and show
3 Add --ref option to CLI commands
4 Update documentation for the --ref flag
Open in Stage

Chapters generated by Stage for commit 42f2a3c on May 14, 2026 2:46am UTC.

@dastratakos dastratakos marked this pull request as ready for review May 14, 2026 03:50
@dastratakos dastratakos merged commit abb50ba into main May 14, 2026
5 checks passed
@dastratakos dastratakos deleted the dastratakos/toggle-untracked-changes branch May 14, 2026 03:50
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment thread packages/cli/src/git.ts
case WORKING_TREE_REF.STAGED:
return ["--cached"];
case WORKING_TREE_REF.WORK:
return [mergeBaseSha];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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