Skip to content

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

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

Merged
merged 4 commits into from
Dec 3, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Using -z and removed unnecessary logic
  • Loading branch information
chomosuke committed Nov 29, 2022
commit 2bb288e7d1735e327afd6bf4ce1a1e75f591b6a7
44 changes: 18 additions & 26 deletions lua/nvim-tree/git/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +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)
local path = line:sub(4, -2)
if utils.str_find(status, "R") then
-- rename have format of "from -> to"
-- we just what the "to" part
if path:sub(1, 1) == '"' then
-- incase " -> " is a part of the file name
local _, j = path:find('" -> "', nil, true)
path = path:sub(j, -1)
else
local _, j = path:find(" -> ", nil, true)
path = path:sub(j + 1, -1)
end
end

-- removing `"` when git is returning special file status containing spaces
if path:sub(1, 1) == '"' then
path = path:sub(2, -2)
path = path:gsub('\\"', '"')
path = path:gsub("\\\\", "\\")
end

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 @@ -63,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 @@ -125,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 Down