Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion src/cmds/git/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,7 @@ fn run_branch(args: &[String], verbose: u8, global_args: &[String]) -> Result<i3
return Ok(result.exit_code);
}

let filtered = filter_branch_output(&result.stdout);
let filtered = format_branch_output(&result.stdout, args);
println!("{}", filtered);

timer.track(
Expand All @@ -1429,6 +1429,14 @@ fn run_branch(args: &[String], verbose: u8, global_args: &[String]) -> Result<i3
Ok(0)
}

fn format_branch_output(output: &str, args: &[String]) -> String {
if args.iter().any(|a| a == "-a" || a == "--all") {
output.trim_end().to_string()
} else {
filter_branch_output(output)
}
}

fn filter_branch_output(output: &str) -> String {
let mut current = String::new();
let mut local: Vec<String> = Vec::new();
Expand Down Expand Up @@ -2195,6 +2203,36 @@ mod tests {
);
}

#[test]
fn test_format_branch_output_preserves_explicit_all_remote_refs() {
let output =
"* main\n remotes/origin/HEAD -> origin/main\n remotes/origin/main\n";

for flag in ["-a", "--all"] {
let result = format_branch_output(output, &[flag.to_string()]);

assert!(
result.contains("remotes/origin/main"),
"explicit {} should preserve remote-tracking refs:\n{}",
flag,
result
);
}
}

#[test]
fn test_format_branch_output_keeps_default_compact_deduping() {
let output =
"* main\n remotes/origin/HEAD -> origin/main\n remotes/origin/main\n";
let result = format_branch_output(output, &[]);

assert!(
!result.contains("remotes/origin/main"),
"default compact branch output should still dedupe matching remotes:\n{}",
result
);
}

#[test]
fn test_filter_stash_list() {
let output =
Expand Down