Skip to content

Commit

Permalink
fix(git): git rename not showing up for the renamed file (#1783)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
chomosuke authored Dec 3, 2022
1 parent 9d9c571 commit f8489c9
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lua/nvim-tree/git/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,34 @@ local utils = require "nvim-tree.utils"
local Runner = {}
Runner.__index = Runner

function Runner:_parse_status_output(line)
local status = line:sub(1, 2)
-- removing `"` when git is returning special file status containing spaces
local path = line:sub(4, -2):gsub('^"', ""):gsub('"$', "")
function Runner:_parse_status_output(status, path)
-- replacing slashes if on windows
if vim.fn.has "win32" == 1 then
path = path:gsub("/", "\\")
end
if #status > 0 and #path > 0 then
self.output[utils.path_remove_trailing(utils.path_join { self.project_root, path })] = status
end
return #line
end

function Runner:_handle_incoming_data(prev_output, incoming)
if incoming and utils.str_find(incoming, "\n") then
local prev = prev_output .. incoming
local i = 1
local skip_next_line = false
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

return prev:sub(i, -1)
Expand All @@ -44,7 +52,7 @@ function Runner:_getopts(stdout_handle, stderr_handle)
local untracked = self.list_untracked and "-u" or nil
local ignored = (self.list_untracked and self.list_ignored) and "--ignored=matching" or "--ignored=no"
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,
stdio = { nil, stdout_handle, stderr_handle },
}
Expand Down Expand Up @@ -106,6 +114,9 @@ function Runner:_run_git_job()
if err then
return
end
if data then
data = data:gsub("%z", "\n")
end
self:_log_raw_output(data)
output_leftover = self:_handle_incoming_data(output_leftover, data)
end
Expand All @@ -122,6 +133,7 @@ function Runner:_wait()
local function is_done()
return self.rc ~= nil
end

while not vim.wait(30, is_done) do
end
end
Expand Down

0 comments on commit f8489c9

Please sign in to comment.