Skip to content

Commit 245cf1e

Browse files
authored
fix: hide gitignored and apply show git status when non-ascii characters are present in path (#741)
1 parent 7943df0 commit 245cf1e

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

lua/neo-tree/git/ignored.lua

+7-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ M.mark_ignored = function(state, items, callback)
5959
if utils.is_windows then
6060
--on Windows, git seems to return quotes and double backslash "path\\directory"
6161
result = vim.tbl_map(function(item)
62-
item = item:gsub('"', "")
6362
item = item:gsub("\\\\", "\\")
6463
return item
6564
end, result)
@@ -74,6 +73,13 @@ M.mark_ignored = function(state, items, callback)
7473
end
7574
end
7675
end
76+
result = vim.tbl_map(function(item)
77+
-- remove leading and trailing " from git output
78+
item = item:gsub('^"', ""):gsub('"$', "")
79+
-- convert octal encoded lines to utf-8
80+
item = git_utils.octal_to_utf8(item)
81+
return item
82+
end, result)
7783
return result
7884
end
7985

lua/neo-tree/git/status.lua

+5-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,11 @@ local parse_git_status_line = function(context, line)
7373
relative_path = line_parts[3]
7474
end
7575

76-
-- remove any " due to whitespace in the path
77-
relative_path = relative_path:gsub('^"', ""):gsub('$"', "")
76+
-- remove any " due to whitespace or utf-8 in the path
77+
relative_path = relative_path:gsub('^"', ""):gsub('"$', "")
78+
-- convert octal encoded lines to utf-8
79+
relative_path = git_utils.octal_to_utf8(relative_path)
80+
7881
if utils.is_windows == true then
7982
relative_path = utils.windowize_path(relative_path)
8083
end

lua/neo-tree/git/utils.lua

+8
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,12 @@ M.get_repository_root = function(path, callback)
4848
end
4949
end
5050

51+
M.octal_to_utf8 = function(text)
52+
-- git uses octal encoding for utf-8 filepaths, convert octal back to utf-8
53+
text = text:gsub("\\([0-7][0-7][0-7])", function(octal)
54+
return string.char(tonumber(octal, 8))
55+
end)
56+
return text
57+
end
58+
5159
return M

0 commit comments

Comments
 (0)