Skip to content
Merged
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
12 changes: 11 additions & 1 deletion src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ fn run_diff(
let mut cmd = git_cmd(global_args);
cmd.arg("diff");
for arg in args {
if arg == "--no-compact" {
continue; // RTK flag, not a git flag
}
cmd.arg(arg);
}

Expand Down Expand Up @@ -279,6 +282,7 @@ pub(crate) fn compact_diff(diff: &str, max_lines: usize) -> String {
let mut in_hunk = false;
let mut hunk_lines = 0;
let max_hunk_lines = 30;
let mut was_truncated = false;

for line in diff.lines() {
if line.starts_with("diff --git") {
Expand All @@ -287,7 +291,7 @@ pub(crate) fn compact_diff(diff: &str, max_lines: usize) -> String {
result.push(format!(" +{} -{}", added, removed));
}
current_file = line.split(" b/").nth(1).unwrap_or("unknown").to_string();
result.push(format!("\n📄 {}", current_file));
result.push(format!("\n{}", current_file));
added = 0;
removed = 0;
in_hunk = false;
Expand Down Expand Up @@ -321,11 +325,13 @@ pub(crate) fn compact_diff(diff: &str, max_lines: usize) -> String {
if hunk_lines == max_hunk_lines {
result.push(" ... (truncated)".to_string());
hunk_lines += 1;
was_truncated = true;
}
}

if result.len() >= max_lines {
result.push("\n... (more changes truncated)".to_string());
was_truncated = true;
break;
}
}
Expand All @@ -334,6 +340,10 @@ pub(crate) fn compact_diff(diff: &str, max_lines: usize) -> String {
result.push(format!(" +{} -{}", added, removed));
}

if was_truncated {
result.push("[full diff: rtk git diff --no-compact]".to_string());
}

result.join("\n")
}

Expand Down
Loading