mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 18:58:12 +00:00
fix(git): use nul char as separator for git status
This commit is contained in:
parent
e3c5944421
commit
8e0dfd2856
3 changed files with 7 additions and 2 deletions
|
@ -56,6 +56,7 @@ function M.update(cwd, opts)
|
|||
"-uall",
|
||||
"--porcelain=v1",
|
||||
"--ignored=matching",
|
||||
"-z",
|
||||
},
|
||||
}, function()
|
||||
stdout:close()
|
||||
|
@ -71,7 +72,7 @@ function M.update(cwd, opts)
|
|||
return
|
||||
end
|
||||
local ret = {} ---@type snacks.explorer.git.Status[]
|
||||
for _, line in ipairs(vim.split(output, "\r?\n")) do
|
||||
for _, line in ipairs(vim.split(output, "\0")) do
|
||||
if line ~= "" then
|
||||
local status, file = line:sub(1, 2), line:sub(4)
|
||||
ret[#ret + 1] = {
|
||||
|
|
|
@ -106,6 +106,7 @@ function M.status(opts, ctx)
|
|||
"status",
|
||||
"-uall",
|
||||
"--porcelain=v1",
|
||||
"-z",
|
||||
}
|
||||
if opts.ignored then
|
||||
table.insert(args, "--ignored=matching")
|
||||
|
@ -116,6 +117,7 @@ function M.status(opts, ctx)
|
|||
return require("snacks.picker.source.proc").proc({
|
||||
opts,
|
||||
{
|
||||
sep = "\0",
|
||||
cwd = cwd,
|
||||
cmd = "git",
|
||||
args = args,
|
||||
|
|
|
@ -9,6 +9,7 @@ local islist = vim.islist or vim.tbl_islist
|
|||
|
||||
---@class snacks.picker.proc.Config: snacks.picker.Config
|
||||
---@field cmd string
|
||||
---@field sep? string
|
||||
---@field args? string[]
|
||||
---@field env? table<string, string>
|
||||
---@field cwd? string
|
||||
|
@ -37,6 +38,7 @@ function M.proc(opts, ctx)
|
|||
end
|
||||
end
|
||||
|
||||
local sep = opts.sep or "\n"
|
||||
local aborted = false
|
||||
local stdout = assert(uv.new_pipe())
|
||||
|
||||
|
@ -93,7 +95,7 @@ function M.proc(opts, ctx)
|
|||
end
|
||||
local from = 1
|
||||
while from <= #data do
|
||||
local nl = data:find("\n", from, true)
|
||||
local nl = data:find(sep, from, true)
|
||||
if nl then
|
||||
local cr = data:byte(nl - 1, nl - 1) == 13 -- \r
|
||||
local line = data:sub(from, nl - (cr and 2 or 1))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue