Skip to content
Open
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
2 changes: 2 additions & 0 deletions lua/neogit/lib/git/cli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ end
---@field exclude_standard self
---@field full_name self
---@field error_unmatch self
---@field eol self

---@class GitCommandLsTree: GitCommandBuilder
---@field full_tree self
Expand Down Expand Up @@ -950,6 +951,7 @@ local configurations = {
exclude_standard = "--exclude-standard",
full_name = "--full-name",
error_unmatch = "--error-unmatch",
eol = "--eol",
},
},

Expand Down
24 changes: 21 additions & 3 deletions lua/neogit/lib/git/index.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
local git = require("neogit.lib.git")
local Path = require("neogit.lib.path")
local util = require("neogit.lib.util")
local crlf = "\r\n"
local lf = "\n"

---@param path string
---@return string
local function eol_character(path)
local _, output = next(git.cli["ls-files"].eol.files(path).call { await = true }.stdout)

if output ~= nil then
local _, _, match = output:find("i/(%w+)")

if match ~= nil then
if match == 'crlf' then
return crlf
elseif match == 'lf' then
return lf
end
end
end

-- Handle the `mixed` line ending case OR lack of a file in the index by deferring to platform defaults for EOL
-- or by reading the current working file and determining its line ending that way
if not Path:new(path):exists() then
return (vim.fn.has("win32") == 1 or vim.fn.has("win64") == 1) and "\r\n" or "\n"
return (vim.fn.has("win32") == 1 or vim.fn.has("win64") == 1) and crlf or lf
end
local lines = vim.fn.readfile(path, "b", 1)
if lines[1] and lines[1]:find("\r") then
return "\r\n"
return crlf
else
return "\n"
return lf
end
end

Expand Down