Skip to content

fix(git): passthrough git branch -v/-vv/--verbose in list mode (#1499) - #1502

Closed
truffle-dev wants to merge 1 commit into
rtk-ai:developfrom
truffle-dev:fix/branch-vv-passthrough-develop-v2
Closed

truffle-dev wants to merge 1 commit into
rtk-ai:developfrom
truffle-dev:fix/branch-vv-passthrough-develop-v2

Conversation

@truffle-dev

Copy link
Copy Markdown

Closes #1499. Supersedes #1500 (retargets to develop per CONTRIBUTING).

Cause

run_branch list mode always runs filter_branch_output, which compresses git branch -a-shaped output into a compact * current + locals + remote-only block. When the user asks for -v/-vv/--verbose, the filter still ran, stripping the commit hash, [origin/...] upstream marker, and subject that -v exists to show. From git's point of view the flag had no effect.

The -v flag reaches run_branch through two different paths depending on position:

  1. trailing position (rtk git branch --list -v): clap's trailing_var_arg = true on Branch { args } captures -v inside args.
  2. leading position (rtk git branch -vv): rtk's own -v / --verbose is declared global = true on Cli, so clap consumes the -vv before the subcommand is parsed. args arrives empty and cli.verbose == 2.

The original fix only covered case 1, but the repro in #1499 is case 2, so the second branch was needed. A small debug build confirmed the split:

$ rtk git branch -vv          → args=[], verbose=2
$ rtk git branch --verbose    → args=[], verbose=1
$ rtk git branch -a -v        → args=["-a","-v"], verbose=0

Fix

is_verbose_branch_list(args) recognizes --verbose and short-flag groups (so -v, -vv, -va, -av, -avv all match) while rejecting look-alikes such as --vim, --verify-signatures, and positional branch names containing v. For the case-2 path we inject -v<N> before forwarding to git so the child process actually sees the flag. Either signal flips has_verbose_intent, which bypasses filter_branch_output and forwards git's raw output unchanged.

Trade-off: rtk -v git branch (rtk-verbose-as-trace) now also forwards -v to git and shows verbose branch info. This reads as 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 -v near git branch actually wants.

Before / after

Against a small test repo with one local tracking origin/main (gone) and one local tracking origin/feature-1 (gone):

$ target/release/rtk-master git branch -vv
git branch
* main
  feature-1

$ target/release/rtk-fix git branch -vv
git branch
  feature-1 7b78477 [origin/feature-1: gone] feature work
* main      8c70500 [origin/main: gone] init

$ RTK_DISABLED=1 git branch -vv
  feature-1 7b78477 [origin/feature-1: gone] feature work
* main      8c70500 [origin/main: gone] init

Negative path verified: rtk git branch and rtk git branch -a still produce the compact filter output.

Tests

Six new unit tests for is_verbose_branch_list covering canonical spellings, combined short-flag groups, no-verbose cases, long flags containing v, and positional names containing v:

test cmds::git::git::tests::test_is_verbose_branch_list_canonical_flags ... ok
test cmds::git::git::tests::test_is_verbose_branch_list_combined_with_list_flags ... ok
test cmds::git::git::tests::test_is_verbose_branch_list_combined_short_flag_group ... ok
test cmds::git::git::tests::test_is_verbose_branch_list_no_verbose ... ok
test cmds::git::git::tests::test_is_verbose_branch_list_does_not_match_long_flags_with_v ... ok
test cmds::git::git::tests::test_is_verbose_branch_list_does_not_match_positional_containing_v ... ok

Full suite on develop: cargo test --bin rtk --release → 1684 passed, 6 ignored, 0 failed on rust:1.95. cargo fmt --all -- --check clean. cargo clippy --bin rtk introduces zero new issues vs develop.

Scope

Only run_branch list mode. --show-current, write-path (-d / -D / -m / -M / rename / upstream edit), and branch creation are untouched. The compact filter_branch_output is unchanged so the 80%+ savings on bare git branch -a stay intact.

…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.
@CLAassistant

CLAassistant commented Apr 24, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@pszymkowiak pszymkowiak added bug Something isn't working effort-small Quelques heures, 1 fichier filter-quality Filter produces incorrect/truncated signal labels Apr 24, 2026
@pszymkowiak

Copy link
Copy Markdown
Collaborator

[w] wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes git branch verbose flags (-v/-vv/--verbose) being silently stripped by rtk's compact filter in list mode. The fix detects verbose intent from both trailing args and rtk's global --verbose flag, bypasses the filter, and forwards the flag to the git child process so commit hashes, upstream markers, and subjects are displayed.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #1499


Analyzed automatically by wshm · This is an automated analysis, not a human review.

@truffle-dev

Copy link
Copy Markdown
Author

19 days in against develop, CI green, wshm flagged this as a low-risk bug-fix on a high-priority issue. Happy to rebase if develop has drifted, or split the case-1 / case-2 detection into separate commits if that reads cleaner. Anything blocking on my side?

@truffle-dev

Copy link
Copy Markdown
Author

Closing this for now. Sat 35 days with no movement past the initial wshm triage. Happy to revisit if the git branch -v/-vv/--verbose passthrough is wanted later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working effort-small Quelques heures, 1 fichier filter-quality Filter produces incorrect/truncated signal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk git branch -vv strips commit hashes, tracking markers, and remote metadata — filter has no -vv awareness

3 participants