diff --git a/lua/gitsigns/git.lua b/lua/gitsigns/git.lua index 18dbbaa..52c3f44 100644 --- a/lua/gitsigns/git.lua +++ b/lua/gitsigns/git.lua @@ -27,13 +27,14 @@ function M.file_info(file, toplevel) }, cwd = toplevel, on_stdout = function(_, line) - local parts = vim.split(line, '%s+') + local parts = vim.split(line, '\t') if #parts > 1 then - stage = tonumber(parts[3]) + relpath = parts[2] + local attrs = vim.split(parts[1], '%s+') + stage = tonumber(attrs[3]) if stage <= 1 then - mode_bits = parts[1] - object_name = parts[2] - relpath = parts[4] + mode_bits = attrs[1] + object_name = attrs[2] else has_conflict = true end @@ -41,7 +42,7 @@ function M.file_info(file, toplevel) relpath = parts[1] end end, - on_exit = function(_, _) + on_exit = function() callback(relpath, object_name, mode_bits, has_conflict) end, }) diff --git a/teal/gitsigns/git.tl b/teal/gitsigns/git.tl index 2f2b4f3..dcccb53 100644 --- a/teal/gitsigns/git.tl +++ b/teal/gitsigns/git.tl @@ -27,21 +27,22 @@ function M.file_info(file: string, toplevel: string): cb_function }, cwd = toplevel, on_stdout = function(_, line: string) - local parts = vim.split(line, '%s+') - if #parts > 1 then - stage = tonumber(parts[3]) + local parts = vim.split(line, '\t') + if #parts > 1 then -- tracked file + relpath = parts[2] + local attrs = vim.split(parts[1], '%s+') + stage = tonumber(attrs[3]) if stage <= 1 then - mode_bits = parts[1] - object_name = parts[2] - relpath = parts[4] + mode_bits = attrs[1] + object_name = attrs[2] else has_conflict = true end - else + else -- untracked file relpath = parts[1] end end, - on_exit = function(_, _) + on_exit = function() callback(relpath, object_name, mode_bits, has_conflict) end } diff --git a/test/gitsigns_spec.lua b/test/gitsigns_spec.lua index 6d5e7d4..4fa7a1b 100644 --- a/test/gitsigns_spec.lua +++ b/test/gitsigns_spec.lua @@ -730,6 +730,41 @@ local function testsuite(variant, advanced_features) end) + it('handle files with spaces', function() + screen:try_resize(20,6) + exec_lua('gs.setup(...)', test_config) + command("set signcolumn=yes") + + local spacefile = scratch..'/a b c d' + + write_to_file(spacefile, {'spaces', 'in', 'file'}) + + edit(spacefile) + + screen:expect{grid=[[ + {3:+ }^spaces | + {3:+ }in | + {3:+ }file | + {6:~ }| + {6:~ }| + | + ]]} + + git{'add', spacefile} + sleep(100) + edit(spacefile) + + screen:expect{grid=[[ + {1: }^spaces | + {1: }in | + {1: }file | + {6:~ }| + {6:~ }| + | + ]]} + + end) + end) end