diff --git a/src/cmds/git/git.rs b/src/cmds/git/git.rs index eaf8d8b5f..4aa19695f 100644 --- a/src/cmds/git/git.rs +++ b/src/cmds/git/git.rs @@ -1416,7 +1416,7 @@ fn run_branch(args: &[String], verbose: u8, global_args: &[String]) -> Result Result 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 = Vec::new(); @@ -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 =