feat(cli): add --color-only filter mode for git diffFilter - #745
Open
YuriNachos wants to merge 1 commit into
Open
feat(cli): add --color-only filter mode for git diffFilter#745YuriNachos wants to merge 1 commit into
YuriNachos wants to merge 1 commit into
Conversation
Git reaches interactive staging (`git add -p`, `git stash -p`, `git reset -p`) through `interactive.diffFilter`: a non-interactive text transform whose stdout Git re-parses to drive its own prompts, so any interactive Hunk command hangs the flow. `hunk --color-only` (also `hunk pager --color-only`) reads a unified diff from stdin, applies Hunk's diff coloring and Pierre syntax highlighting, writes ANSI output to stdout, and exits -- no TTY, no alternate screen. The raw input lines stay the source of truth so the output remains a structurally valid diff (byte-identical after ANSI stripping, tabs included); the parsed model and highlight rows only pick colors, and any line that fails to align falls back to whole-line theme colors. Non-diff input passes through unchanged so a misconfigured filter can never corrupt a Git pipeline. Closes modem-dev#575. Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
|
PR author is not in the allowed authors list. |
|
@YuriNachos is attempting to deploy a commit to the Modem Team on Vercel. A member of the Team first needs to authorize it. |
Member
|
Thanks for tackling this—the overall approach looks good, and the focused tests pass locally. I found a few issues to address before merging:
Happy to recheck after an update. This comment was generated by Pi using gpt-5.6-sol |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
hunk --color-onlyreads a unified diff from stdin, applies Hunk's diff coloring and syntax highlighting, and writes the ANSI-colored diff to stdout — no interactive UI, no TTY, no alternate screen. Also available ashunk pager --color-only.Why
Closes #575. Hunk works great as
core.pager, butgit add -p/git stash -p/git reset -preach their diffs throughinteractive.diffFilter— a non-interactive text transform that Git re-parses to drive its own prompts. Pointing that config at any interactive Hunk command hangs the staging flow, so users migrating from delta have to keep delta installed just for its--color-only(git config interactive.diffFilter "delta --color-only"). @jesseleite also noted in #575 that a non-interactive colored render enables piping themed hunk output into an fzf preview window without a wrapper script.How
src/ui/colorOnlyFilter.ts, built on Hunk's existing parse/highlight stack (loadAppBootstrap→ PierreloadHighlightedDiff/buildStackRows→ theme palettes). There is no second diff engine: the raw stdin lines stay the source of truth and the parsed model only picks colors. That matters becausegit add -pre-parses filter stdout — after stripping ANSI escapes, the output is byte-identical to the input (tabs included). Highlight spans are trusted only when they reconstruct the line exactly; anything that fails to align falls back to whole-line theme colors, and non-diff input passes through unchanged so a misconfigured filter can never corrupt a Git pipeline.hunkdiff/static), while this PR ships the CLI flag the issue asks for, built on the same internal rendering path. If feat: export static diff renderer #686 lands,--color-onlycan adopt the exported entry without changing its contract.Verification
bun run typecheck,bun run lint,bun run format:checkclean; 17 new unit tests across the renderer, CLI parsing, and startup wiring (bun test src/ui/colorOnlyFilter.test.ts src/app/startup.test.ts src/core/cli.test.ts→ 150 pass / 0 fail), including the strip-ANSI-equals-input invariant, byte-identical passthrough for non-diff input, recoloring of pre-colored (ANSI) diff input, and tab-indented content bytes.diff <(hunk --color-only < sample.patch | strip-ansi) sample.patch→ identical, for plain and pre-colored input.git add -pend-to-end withinteractive.diffFilter = hunk --color-only: Git re-parses the colored hunk and drives its prompt normally (verified withprintf 'q\n' | git add -p).Closes #575. Related: #686, #247.
🤖 Generated with Claude Code