From 4d4bb7e583a053dc8ade2b500355d8535cb686d4 Mon Sep 17 00:00:00 2001 From: Mbutu Date: Sun, 1 Sep 2024 23:33:38 +0200 Subject: [PATCH] fixed infinite loop freeze caused by the way paths are handled in the while loop --- lua/parrot/file_utils.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lua/parrot/file_utils.lua b/lua/parrot/file_utils.lua index b131583..3c20e88 100644 --- a/lua/parrot/file_utils.lua +++ b/lua/parrot/file_utils.lua @@ -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