Skip to content

Commit 7eb91da

Browse files
committed
fix: git root search infinite loop on windows (issue: #126)
1 parent 9fcd990 commit 7eb91da

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lua/gp/helper.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,18 @@ _H.find_git_root = function(path)
175175
if path then
176176
cwd = vim.fn.fnamemodify(path, ":p:h")
177177
end
178-
while cwd ~= "/" do
178+
179+
for _ = 0, 1000 do
179180
local files = vim.fn.readdir(cwd)
180181
if vim.tbl_contains(files, ".git") then
181182
logger.debug("found git root: " .. cwd)
182183
return cwd
183184
end
184-
cwd = vim.fn.fnamemodify(cwd, ":h")
185+
local parent = vim.fn.fnamemodify(cwd, ":h")
186+
if parent == cwd then
187+
break
188+
end
189+
cwd = parent
185190
end
186191
logger.debug("git root not found")
187192
return ""

0 commit comments

Comments
 (0)