Skip to content

Commit

Permalink
fixed infinite loop freeze caused by the way paths are handled in the…
Browse files Browse the repository at this point in the history
… while loop
  • Loading branch information
Mbutu committed Sep 1, 2024
1 parent 4a50b58 commit 4d4bb7e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lua/parrot/file_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ end
---@return string # returns the path of the git root dir or an empty string if not found
M.find_git_root = function()
local cwd = vim.fn.expand("%:p:h")
local git_dir = cwd .. "/.git"
while cwd ~= "/" do
if vim.fn.isdirectory(git_dir) == 1 then
while cwd ~= "" do
if vim.fn.isdirectory(cwd .. "/.git") == 1 then
return cwd
end
cwd = vim.fn.fnamemodify(cwd, ":h")
git_dir = cwd .. "/.git"
local parent = vim.fn.fnamemodify(cwd, ":h")
if parent == cwd then
break
end
cwd = parent
end
return ""
end
Expand Down

0 comments on commit 4d4bb7e

Please sign in to comment.