From ebb38b75a262f4497198d348037c0821bf0de523 Mon Sep 17 00:00:00 2001 From: Sedge Bot Date: Thu, 7 May 2026 17:33:40 -0500 Subject: [PATCH] Handle no-newline diff markers --- src/fmt.zig | 6 ++++++ tests/conformance.sh | 13 +++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/fmt.zig b/src/fmt.zig index 4605c5b..0e71699 100644 --- a/src/fmt.zig +++ b/src/fmt.zig @@ -6,6 +6,10 @@ const color = @import("color.zig"); const Writer = std.Io.Writer; +fn writeNoNewlineMarker(w: *Writer) !void { + try w.writeAll("\n\\ No newline at end of file\n"); +} + // --- Compact diff callback --- pub const CompactCtx = struct { @@ -48,6 +52,7 @@ pub fn compactCallback( } } }, + '<', '>', '=' => writeNoNewlineMarker(w) catch return -1, else => {}, } return 0; @@ -139,6 +144,7 @@ pub fn humanCallback( w.writeAll(slice) catch return -1; } }, + '<', '>', '=' => writeNoNewlineMarker(w) catch return -1, else => {}, } return 0; diff --git a/tests/conformance.sh b/tests/conformance.sh index 9383b88..f3bb1af 100755 --- a/tests/conformance.sh +++ b/tests/conformance.sh @@ -285,13 +285,18 @@ check "deleted file diff lines" \ cp main_backup.py main.py rm main_backup.py -# No trailing newline - known issue: nit's buffered writer doesn't -# insert a newline when the file lacks one, causing lines to run together. -# TODO: handle GIT_DIFF_LINE_DEL_EOFNL / ADD_EOFNL markers +# No trailing newline: compact diff should keep git's marker on its own +# line instead of running the deletion/addition lines together. +git stash -q printf "no newline" > nonewline.txt git add nonewline.txt +git commit -q -m "Add no-newline fixture" printf "no newline changed" > nonewline.txt -git reset -q nonewline.txt +check "no trailing newline markers" \ + "git diff -U1 | grep -E '^[-+]no newline|^\\\\ No newline'" \ + "$NIT diff | grep -E '^[-+]no newline|^\\\\ No newline'" +git reset --hard -q HEAD~1 +git stash pop -q 2>/dev/null || true rm -f nonewline.txt # --- Show edge cases ---