diff --git a/lua/nvim-tree/git/runner.lua b/lua/nvim-tree/git/runner.lua index 686b5f80bd5..a03c72e4bca 100644 --- a/lua/nvim-tree/git/runner.lua +++ b/lua/nvim-tree/git/runner.lua @@ -4,10 +4,7 @@ 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("/", "\\") @@ -15,15 +12,26 @@ function Runner:_parse_status_output(line) 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) @@ -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 }, } @@ -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 @@ -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