Skip to content

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

Open

Description

@cderv

rtk git branch -vv drops commit hashes, the [origin/...] upstream tracking marker, and commit subjects — the very information -vv exists to show. filter_branch_output is designed around bare git branch -a output and has no handling for the verbose format, so metadata the user explicitly requested is silently discarded.

Reproduction

$ RTK_DISABLED=1 git branch -vv
  feature-a  abc12345 Some commit subject
  feature-b  def67890 Another commit subject
* main       12345678 [origin/main] Latest commit on main

$ rtk git branch -vv
* main
  feature-a
  feature-b
  remote-only (3):
    topic-x
    agent/topic-y-abc123
    topic-z

The upstream marker [origin/main], the commit hashes, and the subjects are gone. From the agent's point of view, git branch -vv is indistinguishable from git branch -a — the flag had no effect.

Cause

-vv isn't in the list-flag set at run_branch, so the command falls through to List mode:

rtk/src/cmds/git/git.rs

Lines 1144 to 1164 in 80a6fe6

// Detect list-mode flags
let has_list_flag = args.iter().any(|a| {
a == "-a"
|| a == "--all"
|| a == "-r"
|| a == "--remotes"
|| a == "--list"
|| a == "--merged"
|| a == "--no-merged"
|| a == "--contains"
|| a == "--no-contains"
|| a == "--format"
|| a.starts_with("--format=")
|| a == "--sort"
|| a.starts_with("--sort=")
|| a == "--points-at"
|| a.starts_with("--points-at=")
});
// Detect positional arguments (not flags) — indicates branch creation
let has_positional_arg = args.iter().any(|a| !a.starts_with('-'));

List mode adds -a --no-color, passes -vv through to git, then pipes the result through filter_branch_output:

rtk/src/cmds/git/git.rs

Lines 1234 to 1261 in 80a6fe6

// List mode: show compact branch list
let mut cmd = git_cmd(global_args);
cmd.arg("branch");
if !has_list_flag {
cmd.arg("-a");
}
cmd.arg("--no-color");
for arg in args {
cmd.arg(arg);
}
let result = exec_capture(&mut cmd).context("Failed to run git branch")?;
if !result.success() {
if !result.stderr.trim().is_empty() {
eprint!("{}", result.stderr);
}
timer.track(
&format!("git branch {}", args.join(" ")),
&format!("rtk git branch {}", args.join(" ")),
&result.stdout,
&result.stdout,
);
return Ok(result.exit_code);
}
let filtered = filter_branch_output(&result.stdout);
println!("{}", filtered);

filter_branch_output was designed for bare git branch -a output (see the test fixtures at lines 1885-1925 — none use -vv format) and reshapes everything into the compact * current + locals + remote-only block shown above. There's no code path that preserves [origin/...] markers or hash + subject when -vv is present:

rtk/src/cmds/git/git.rs

Lines 1273 to 1328 in 80a6fe6

fn filter_branch_output(output: &str) -> String {
let mut current = String::new();
let mut local: Vec<String> = Vec::new();
let mut remote: Vec<String> = Vec::new();
let mut seen_remote: std::collections::HashSet<String> = std::collections::HashSet::new();
for line in output.lines() {
let line = line.trim();
if line.is_empty() {
continue;
}
if let Some(branch) = line.strip_prefix("* ") {
current = branch.to_string();
} else if let Some(rest) = line.strip_prefix("remotes/") {
if let Some(slash_pos) = rest.find('/') {
let branch = &rest[slash_pos + 1..];
if branch.starts_with("HEAD ") {
continue;
}
if seen_remote.insert(branch.to_string()) {
remote.push(branch.to_string());
}
}
} else {
local.push(line.to_string());
}
}
let mut result = Vec::new();
result.push(format!("* {}", current));
if !local.is_empty() {
for b in &local {
result.push(format!(" {}", b));
}
}
if !remote.is_empty() {
let remote_only: Vec<&String> = remote
.iter()
.filter(|r| *r != &current && !local.contains(r))
.collect();
if !remote_only.is_empty() {
result.push(format!(" remote-only ({}):", remote_only.len()));
for b in remote_only.iter().take(10) {
result.push(format!(" {}", b));
}
if remote_only.len() > 10 {
result.push(format!(" ... +{} more", remote_only.len() - 10));
}
}
}
result.join("\n")
}

Impact

-vv is the canonical way to check upstream tracking state — "does my local branch have an upstream? is it ahead/behind?". When RTK answers the agent's git branch -vv with bare names, the agent has no way to see tracking configuration and may conclude branches have no upstream when they do. RTK_DISABLED=1 git branch -vv works as a workaround, but as with #1474 and #730, the agent only reaches for it once something else tips it off that the output is incomplete.

Suggestion

The project's own design philosophy covers this case:

When a user or LLM explicitly requests detailed output via flags (e.g., git log --comments, cargo test -- --nocapture, ls -la), respect that intent. Compressing explicitly-requested detail defeats the purpose.

-v / -vv / --verbose fit that rule exactly. One option is to detect those flags in run_branch and passthrough raw. Another is to make filter_branch_output aware of the verbose format and preserve the hash + tracking marker + subject per line. Passthrough is simpler and matches the principle more literally.

Broader Pattern

Same class of bug as #1474, #730, #720 — a filter that isn't flag-aware silently strips content the user asked for, and the hook makes the loss invisible to the agent.

Related

Environment

  • rtk 0.37.2
  • Windows 11 (Git Bash)

Activity

  1. added
    bug
    effort-small
    filter-quality
    good first issue
    on Apr 24, 2026
  2. pszymkowiak commented on Apr 24, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 96%

    Summary

    git branch -vv output is stripped of commit hashes, tracking markers, and subjects by filter_branch_output; fix in PR #1502.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/cmds/git/git.rs

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

  3. cardila-appgate commented on May 22, 2026

    @cardila-appgate

    Additional real-world impact: [gone] branch detection broken

    Adding a concrete scenario where this bug causes a silent, hard-to-diagnose failure: automated stale branch cleanup.

    What happened

    During a repository cleanup session, the agent ran the standard pattern to delete local branches whose remotes have been deleted:

    # Step 1 — identify stale branches
    rtk git branch -vv | grep '\[gone\]'
    
    # Step 2 — delete them
    rtk git branch -vv | grep '\[gone\]' | awk '{print $1}' | while read branch; do
      git branch -D "$branch"
    done

    Step 1 returned no output. The agent (Claude Code) concluded there were no stale branches and skipped cleanup — even though 10 local branches were actually tracking deleted remotes.

    The real output (RTK_DISABLED=1 git branch -vv) showed every one of them with [origin/...: gone].

    Why it's worse in agentic contexts

    Two compounding factors:

    1. Silent failure — grep '\[gone\]' on RTK's compacted output exits 0 with no matches. The agent sees "no output = no stale branches" and moves on. There's no error, no warning, no hint that the upstream markers were stripped.
    2. Pipe subshell — The while read pattern is a common shell idiom for this task. With the filter in place, grep produces nothing, the loop body never runs, and the agent never reaches git branch -D. No deletion, no error — just silent no-op.

    The workaround (/usr/bin/git branch -vv to bypass the hook entirely) only became apparent after the agent tried the standard pattern multiple times and noticed the branch count didn't change.

    Suggested priority signal

    This is a good candidate for the "passthrough when -v/-vv is present" fix mentioned in the issue description. The [gone] marker is specifically a -v/-vv feature — bare git branch never shows it — so any filter that strips it while passing -vv through to git is directly breaking a core use case of that flag.

    Environment

    • rtk 0.41.0 (macOS, zsh, Claude Code hook)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clibugeffort-smallfilter-qualitygood first issueneeds-reproductionplatform:windowspriority:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions