fix(git): git rename not showing up for the renamed file (#1783)
* fixed git rename not showing up for the renamed file * considered " -> " being a part of the filename Fixed -> pattern to escape - Fixed "\"" and "\\" in filename * using string.find(, , true) to match plain -> * Using -z and removed unnecessary logic
This commit is contained in:
@@ -4,10 +4,7 @@ local utils = require "nvim-tree.utils"
|
|||||||
local Runner = {}
|
local Runner = {}
|
||||||
Runner.__index = Runner
|
Runner.__index = Runner
|
||||||
|
|
||||||
function Runner:_parse_status_output(line)
|
function Runner:_parse_status_output(status, path)
|
||||||
local status = line:sub(1, 2)
|
|
||||||
-- removing `"` when git is returning special file status containing spaces
|
|
||||||
local path = line:sub(4, -2):gsub('^"', ""):gsub('"$', "")
|
|
||||||
-- replacing slashes if on windows
|
-- replacing slashes if on windows
|
||||||
if vim.fn.has "win32" == 1 then
|
if vim.fn.has "win32" == 1 then
|
||||||
path = path:gsub("/", "\\")
|
path = path:gsub("/", "\\")
|
||||||
@@ -15,15 +12,26 @@ function Runner:_parse_status_output(line)
|
|||||||
if #status > 0 and #path > 0 then
|
if #status > 0 and #path > 0 then
|
||||||
self.output[utils.path_remove_trailing(utils.path_join { self.project_root, path })] = status
|
self.output[utils.path_remove_trailing(utils.path_join { self.project_root, path })] = status
|
||||||
end
|
end
|
||||||
return #line
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Runner:_handle_incoming_data(prev_output, incoming)
|
function Runner:_handle_incoming_data(prev_output, incoming)
|
||||||
if incoming and utils.str_find(incoming, "\n") then
|
if incoming and utils.str_find(incoming, "\n") then
|
||||||
local prev = prev_output .. incoming
|
local prev = prev_output .. incoming
|
||||||
local i = 1
|
local i = 1
|
||||||
|
local skip_next_line = false
|
||||||
for line in prev:gmatch "[^\n]*\n" do
|
for line in prev:gmatch "[^\n]*\n" do
|
||||||
i = i + self:_parse_status_output(line)
|
if skip_next_line then
|
||||||
|
skip_next_line = false
|
||||||
|
else
|
||||||
|
local status = line:sub(1, 2)
|
||||||
|
local path = line:sub(4, -2)
|
||||||
|
if utils.str_find(status, "R") then
|
||||||
|
-- skip next line if it is a rename entry
|
||||||
|
skip_next_line = true
|
||||||
|
end
|
||||||
|
self:_parse_status_output(status, path)
|
||||||
|
end
|
||||||
|
i = i + #line
|
||||||
end
|
end
|
||||||
|
|
||||||
return prev:sub(i, -1)
|
return prev:sub(i, -1)
|
||||||
@@ -44,7 +52,7 @@ function Runner:_getopts(stdout_handle, stderr_handle)
|
|||||||
local untracked = self.list_untracked and "-u" or nil
|
local untracked = self.list_untracked and "-u" or nil
|
||||||
local ignored = (self.list_untracked and self.list_ignored) and "--ignored=matching" or "--ignored=no"
|
local ignored = (self.list_untracked and self.list_ignored) and "--ignored=matching" or "--ignored=no"
|
||||||
return {
|
return {
|
||||||
args = { "--no-optional-locks", "status", "--porcelain=v1", ignored, untracked, self.path },
|
args = { "--no-optional-locks", "status", "--porcelain=v1", "-z", ignored, untracked, self.path },
|
||||||
cwd = self.project_root,
|
cwd = self.project_root,
|
||||||
stdio = { nil, stdout_handle, stderr_handle },
|
stdio = { nil, stdout_handle, stderr_handle },
|
||||||
}
|
}
|
||||||
@@ -106,6 +114,9 @@ function Runner:_run_git_job()
|
|||||||
if err then
|
if err then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
if data then
|
||||||
|
data = data:gsub("%z", "\n")
|
||||||
|
end
|
||||||
self:_log_raw_output(data)
|
self:_log_raw_output(data)
|
||||||
output_leftover = self:_handle_incoming_data(output_leftover, data)
|
output_leftover = self:_handle_incoming_data(output_leftover, data)
|
||||||
end
|
end
|
||||||
@@ -122,6 +133,7 @@ function Runner:_wait()
|
|||||||
local function is_done()
|
local function is_done()
|
||||||
return self.rc ~= nil
|
return self.rc ~= nil
|
||||||
end
|
end
|
||||||
|
|
||||||
while not vim.wait(30, is_done) do
|
while not vim.wait(30, is_done) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user