Skip to content

Commit 7fbcfa5

Browse files
committed
fix: relative paths with '-' breaking git
relative paths with '-' inside a `string.match` statement were not matching properly due to the nature of lua matching patterns. Replacing '-' with '%-' resolves the issue.
1 parent f906cb0 commit 7fbcfa5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lua/lib/git.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ end
3030

3131
local function is_folder_dirty(relpath)
3232
for _, status in pairs(GIT_STATUS) do
33-
if string.match(status, relpath) ~= nil then return true end
33+
local match_path = relpath:gsub('(%-)', '%%-')
34+
if string.match(status, match_path) ~= nil then return true end
3435
end
3536
end
3637

3738
local function create_git_checker(pattern)
3839
return function(relpath)
3940
for _, status in pairs(GIT_STATUS) do
40-
-- TODO: fix .* as it could be problematic
41-
local ret = string.match(status, '^.. .*' .. relpath)
41+
local match_path = relpath:gsub('(%-)', '%%-')
42+
local ret = string.match(status, '^.. .*' .. match_path)
4243
if ret ~= nil and string.match(ret, pattern) ~= nil then return true end
4344
end
4445
return false

0 commit comments

Comments
 (0)