From 2ef0690767eb733c705e4de56d02c64696a4acc6 Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Sat, 21 Mar 2026 13:51:32 -0700 Subject: [PATCH] fix(gh): skip compact_diff for --name-only/--stat flags in pr diff When `gh pr diff` is called with output-format-changing flags like --name-only, --stat, --name-status, --numstat, or --shortstat, the output is a plain filename/stat list rather than a unified diff. compact_diff() expects diff headers and hunks, so it produces empty output from these formats. Skip filtering and passthrough directly when any of these flags are present. The output is already compact and doesn't benefit from diff compaction. Fixes #730 Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> --- src/gh_cmd.rs | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/src/gh_cmd.rs b/src/gh_cmd.rs index 325adf5b..2477bbd6 100644 --- a/src/gh_cmd.rs +++ b/src/gh_cmd.rs @@ -1118,6 +1118,18 @@ fn pr_merge(args: &[String], _verbose: u8) -> Result<()> { Ok(()) } +/// Flags that change `gh pr diff` output from unified diff to a different format. +/// When present, compact_diff would produce empty output since it expects diff headers. +fn has_non_diff_format_flag(args: &[String]) -> bool { + args.iter().any(|a| { + a == "--name-only" + || a == "--name-status" + || a == "--stat" + || a == "--numstat" + || a == "--shortstat" + }) +} + fn pr_diff(args: &[String], _verbose: u8) -> Result<()> { // --no-compact: pass full diff through (gh CLI doesn't know this flag, strip it) let no_compact = args.iter().any(|a| a == "--no-compact"); @@ -1127,7 +1139,9 @@ fn pr_diff(args: &[String], _verbose: u8) -> Result<()> { .cloned() .collect(); - if no_compact { + // Passthrough when --no-compact or when a format flag changes output away from + // unified diff (e.g. --name-only produces a filename list, not diff hunks). + if no_compact || has_non_diff_format_flag(&gh_args) { return run_passthrough_with_extra("gh", &["pr", "diff"], &gh_args); } @@ -1538,6 +1552,46 @@ mod tests { assert!(!should_passthrough_issue_view(&[])); } + // --- has_non_diff_format_flag tests --- + + #[test] + fn test_non_diff_format_flag_name_only() { + assert!(has_non_diff_format_flag(&["--name-only".into()])); + } + + #[test] + fn test_non_diff_format_flag_stat() { + assert!(has_non_diff_format_flag(&["--stat".into()])); + } + + #[test] + fn test_non_diff_format_flag_name_status() { + assert!(has_non_diff_format_flag(&["--name-status".into()])); + } + + #[test] + fn test_non_diff_format_flag_numstat() { + assert!(has_non_diff_format_flag(&["--numstat".into()])); + } + + #[test] + fn test_non_diff_format_flag_shortstat() { + assert!(has_non_diff_format_flag(&["--shortstat".into()])); + } + + #[test] + fn test_non_diff_format_flag_absent() { + assert!(!has_non_diff_format_flag(&[])); + } + + #[test] + fn test_non_diff_format_flag_regular_args() { + assert!(!has_non_diff_format_flag(&[ + "123".into(), + "--color=always".into() + ])); + } + // --- filter_markdown_body tests --- #[test]