Repository navigation
fix(git): passthrough git branch -v/-vv/--verbose in list mode (#1499) - #1500
Closed
truffle-dev wants to merge 1 commit into
Closed
truffle-dev wants to merge 1 commit into
truffle-dev wants to merge 1 commit into
Conversation
…tk-ai#1499) List mode always ran filter_branch_output, which compresses `git branch -a` shape output into a compact `* current` + locals + `remote-only` block. When the user asked for `-v`/`-vv`/`--verbose` the filter stripped the commit hash, `[origin/...]` upstream marker, and subject that `-v` exists to show. The flag had no effect. Two signals reach run_branch: 1. trailing position (`rtk git branch --list -v`): clap's trailing_var_arg captures `-v` inside args. 2. leading position (`rtk git branch -vv`): rtk's global `--verbose` flag consumes it before the subcommand is parsed, so args is empty but cli.verbose > 0. is_verbose_branch_list handles case 1 and recognizes canonical spellings plus combined short-flag groups (`-va`, `-av`), while rejecting look-alikes (`--vim`, positional names containing `v`). For case 2 we inject `-v<N>` before forwarding to git so the child actually sees the flag. Either source flips has_verbose_intent, which bypasses filter_branch_output and forwards git's raw output. Adds 6 regression tests for the helper.
Collaborator
📊 Automated PR Analysis
SummaryFixes git branch -v/-vv/--verbose passthrough in list mode, which previously had its verbose output stripped by the compact filter. The fix detects verbose intent from both trailing args and rtk's global --verbose flag, bypasses the filter, and injects the flag into the child git process when needed. Review Checklist
Linked issues: #1499 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
Author
|
Superseded by #1502, which retargets the same fix to |
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.
Closes #1499.
Cause
run_branchlist mode always runsfilter_branch_output, which compressesgit branch -a-shaped output into a compact* current+ locals +remote-onlyblock. When the user asks for-v/-vv/--verbose, the filter still ran, stripping the commit hash,[origin/...]upstream marker, and subject that-vexists to show. From git's point of view the flag had no effect.The
-vflag reachesrun_branchthrough two different paths depending on position:rtk git branch --list -v): clap'strailing_var_arg = trueonBranch { args }captures-vinsideargs.rtk git branch -vv): rtk's own-v/--verboseis declaredglobal = trueonCli, so clap consumes the-vvbefore the subcommand is parsed.argsarrives empty andcli.verbose == 2.The original fix I wrote only covered case 1, but the repro in #1499 is case 2, so I had to add the second branch. A small debug build in
/tmpconfirmed the split:Fix
is_verbose_branch_list(args)recognizes--verboseand short-flag groups (so-v,-vv,-va,-av,-avvall match) while rejecting look-alikes such as--vim,--verify-signatures, and positional branch names containingv. For the case-2 path we inject-v<N>before forwarding togitso the child process actually sees the flag. Either signal flipshas_verbose_intent, which bypassesfilter_branch_outputand forwards git's raw output unchanged.Trade-off:
rtk -v git branch(rtk-verbose-as-trace) now also forwards-vto git and shows verbose branch info. I think this is an improvement; the prior behavior (trace line plus compact list) was an accidental product of the clap collision, and the new behavior matches what anyone typing-vneargit branchactually wants.Before / after
Against a small test repo with one local tracking
origin/main(gone) and one local trackingorigin/feature-1(gone):Negative path verified:
rtk git branchandrtk git branch -astill produce the compact filter output.Tests
Six new unit tests for
is_verbose_branch_listcovering canonical spellings, combined short-flag groups, no-verbose cases, long flags containingv, and positional names containingv:Full suite:
cargo test --bin rtk→ 1612 passed, 6 ignored, 0 failed onrust:1.95.cargo fmt --all -- --checkclean.cargo clippy --bin rtkintroduces zero new issues vs master.Scope
Only
run_branchlist mode.--show-current, write-path (-d/-D/-m/-M/ rename / upstream edit), and branch creation are untouched. The compactfilter_branch_outputis unchanged so the 80%+ savings on baregit branch -astay intact.