@@ -4,26 +4,34 @@ local utils = require "nvim-tree.utils"
4
4
local Runner = {}
5
5
Runner .__index = Runner
6
6
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 )
11
8
-- replacing slashes if on windows
12
9
if vim .fn .has " win32" == 1 then
13
10
path = path :gsub (" /" , " \\ " )
14
11
end
15
12
if # status > 0 and # path > 0 then
16
13
self .output [utils .path_remove_trailing (utils .path_join { self .project_root , path })] = status
17
14
end
18
- return # line
19
15
end
20
16
21
17
function Runner :_handle_incoming_data (prev_output , incoming )
22
18
if incoming and utils .str_find (incoming , " \n " ) then
23
19
local prev = prev_output .. incoming
24
20
local i = 1
21
+ local skip_next_line = false
25
22
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
27
35
end
28
36
29
37
return prev :sub (i , - 1 )
@@ -44,7 +52,7 @@ function Runner:_getopts(stdout_handle, stderr_handle)
44
52
local untracked = self .list_untracked and " -u" or nil
45
53
local ignored = (self .list_untracked and self .list_ignored ) and " --ignored=matching" or " --ignored=no"
46
54
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 },
48
56
cwd = self .project_root ,
49
57
stdio = { nil , stdout_handle , stderr_handle },
50
58
}
@@ -106,6 +114,9 @@ function Runner:_run_git_job()
106
114
if err then
107
115
return
108
116
end
117
+ if data then
118
+ data = data :gsub (" %z" , " \n " )
119
+ end
109
120
self :_log_raw_output (data )
110
121
output_leftover = self :_handle_incoming_data (output_leftover , data )
111
122
end
@@ -122,6 +133,7 @@ function Runner:_wait()
122
133
local function is_done ()
123
134
return self .rc ~= nil
124
135
end
136
+
125
137
while not vim .wait (30 , is_done ) do
126
138
end
127
139
end
0 commit comments