Skip to content

Commit f8489c9

Browse files
authored
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
1 parent 9d9c571 commit f8489c9

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

lua/nvim-tree/git/runner.lua

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,34 @@ local utils = require "nvim-tree.utils"
44
local Runner = {}
55
Runner.__index = Runner
66

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

2117
function Runner:_handle_incoming_data(prev_output, incoming)
2218
if incoming and utils.str_find(incoming, "\n") then
2319
local prev = prev_output .. incoming
2420
local i = 1
21+
local skip_next_line = false
2522
for line in prev:gmatch "[^\n]*\n" do
26-
i = i + self:_parse_status_output(line)
23+
if skip_next_line then
24+
skip_next_line = false
25+
else
26+
local status = line:sub(1, 2)
27+
local path = line:sub(4, -2)
28+
if utils.str_find(status, "R") then
29+
-- skip next line if it is a rename entry
30+
skip_next_line = true
31+
end
32+
self:_parse_status_output(status, path)
33+
end
34+
i = i + #line
2735
end
2836

2937
return prev:sub(i, -1)
@@ -44,7 +52,7 @@ function Runner:_getopts(stdout_handle, stderr_handle)
4452
local untracked = self.list_untracked and "-u" or nil
4553
local ignored = (self.list_untracked and self.list_ignored) and "--ignored=matching" or "--ignored=no"
4654
return {
47-
args = { "--no-optional-locks", "status", "--porcelain=v1", ignored, untracked, self.path },
55+
args = { "--no-optional-locks", "status", "--porcelain=v1", "-z", ignored, untracked, self.path },
4856
cwd = self.project_root,
4957
stdio = { nil, stdout_handle, stderr_handle },
5058
}
@@ -106,6 +114,9 @@ function Runner:_run_git_job()
106114
if err then
107115
return
108116
end
117+
if data then
118+
data = data:gsub("%z", "\n")
119+
end
109120
self:_log_raw_output(data)
110121
output_leftover = self:_handle_incoming_data(output_leftover, data)
111122
end
@@ -122,6 +133,7 @@ function Runner:_wait()
122133
local function is_done()
123134
return self.rc ~= nil
124135
end
136+
125137
while not vim.wait(30, is_done) do
126138
end
127139
end

0 commit comments

Comments
 (0)