Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions src/fmt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -48,6 +52,7 @@ pub fn compactCallback(
}
}
},
'<', '>', '=' => writeNoNewlineMarker(w) catch return -1,
else => {},
}
return 0;
Expand Down Expand Up @@ -139,6 +144,7 @@ pub fn humanCallback(
w.writeAll(slice) catch return -1;
}
},
'<', '>', '=' => writeNoNewlineMarker(w) catch return -1,
else => {},
}
return 0;
Expand Down
13 changes: 9 additions & 4 deletions tests/conformance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---
Expand Down
Loading