Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed: git rename not showing up for the renamed file #1783

Merged
merged 4 commits into from
Dec 3, 2022
Merged
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
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
Copy link
Member

Choose a reason for hiding this comment

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

Interesting that -z swaps from and to... It works.

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 },
Copy link
Member

Choose a reason for hiding this comment

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

Fantastic! Thank you.

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