Skip to content
Open
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
11 changes: 10 additions & 1 deletion runtime/plugins/diff/diff.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Comment on lines -13 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use

diffBase, err = shell.ExecCommand("git", "-C", dirName, "cat-file", "--filters", "HEAD:./" .. fileName)

regardless of autocrlf?

if err ~= nil then
diffBase = buf:Bytes()
end
Expand Down