From 46320732d8bee28d8276ca0f0bbe1b47e67f81c6 Mon Sep 17 00:00:00 2001 From: Abdullah Danisman <46599537+adanisman@users.noreply.github.com> Date: Tue, 17 Mar 2026 12:11:10 +0300 Subject: [PATCH] Fix: Ignore automated formatting changes in authorship (fixes #725) --- src/authorship/attribution_tracker.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/authorship/attribution_tracker.rs b/src/authorship/attribution_tracker.rs index 04cec0e25..7efdc0b2d 100644 --- a/src/authorship/attribution_tracker.rs +++ b/src/authorship/attribution_tracker.rs @@ -1013,9 +1013,25 @@ impl AttributionTracker { let is_whitespace_only = data_is_whitespace(diff.data()); let contains_newline = diff.data().contains(&b'\n'); let is_formatting_pair = prev_whitespace_delete && is_whitespace_only; - #[allow(clippy::if_same_then_else)] - let (author_id, attribution_ts) = if contains_newline { + let (author_id, attribution_ts) = if contains_newline && is_substantive_insert + { + // New substantive line content — attribute to current author (current_author.to_string(), ts) + } else if contains_newline && !is_substantive_insert { + // Line re-inserted with only formatting/whitespace changes (e.g. by a + // code formatter like `mvn spotless:apply`). Preserve the original + // attribution instead of crediting the human author. + if let Some(attr) = find_attribution_for_insertion( + old_attributions, + old_pos, + &mut insertion_attr_cursor, + ) { + (attr.author_id.clone(), attr.ts) + } else if let Some(attr) = new_attributions.last() { + (attr.author_id.clone(), attr.ts) + } else { + (current_author.to_string(), ts) + } } else if is_substantive_insert { (current_author.to_string(), ts) } else if is_formatting_pair {