From e27bbe1939096ed59244849d49f572879e93e6e1 Mon Sep 17 00:00:00 2001 From: mroldao Date: Tue, 11 Nov 2025 19:31:38 +0000 Subject: [PATCH] gutter diff uses 'git cat-file' for autocrlf filter --- runtime/plugins/diff/diff.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/runtime/plugins/diff/diff.lua b/runtime/plugins/diff/diff.lua index f64d8a78ea..920171fa17 100644 --- a/runtime/plugins/diff/diff.lua +++ b/runtime/plugins/diff/diff.lua @@ -10,7 +10,16 @@ function onBufferOpen(buf) local _, err = os.Stat(buf.AbsPath) if err == nil then local dirName, fileName = filepath.Split(buf.AbsPath) - local diffBase, err = shell.ExecCommand("git", "-C", dirName, "show", "HEAD:./" .. fileName) + + local autocrlf, err = shell.ExecCommand("git", "-C", dirName, "config", "get", "core.autocrlf") + + local diffBase + if not err and string.match(autocrlf, "true") then + diffBase, err = shell.ExecCommand("git", "-C", dirName, "cat-file", "--filters", "HEAD:./" .. fileName) + else + diffBase, err = shell.ExecCommand("git", "-C", dirName, "show", "HEAD:./" .. fileName) + end + if err ~= nil then diffBase = buf:Bytes() end