mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-07-21 12:45:13 +00:00
feat(util): add find_git_root function
Add utility function to traverse up directory tree and find git repository root by checking for .git directory.
This commit is contained in:
parent
6c3bda4aca
commit
6db4274a36
1 changed files with 11 additions and 0 deletions
|
@ -228,6 +228,17 @@ function M.walk(path, fn)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param path string
|
||||||
|
function M.find_git_root(path)
|
||||||
|
local current = path
|
||||||
|
while current and current ~= "/" do
|
||||||
|
if vim.fn.isdirectory(current .. "/.git") == 1 then
|
||||||
|
return current
|
||||||
|
end
|
||||||
|
current = vim.fn.fnamemodify(current, ":h")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
---@param root string
|
---@param root string
|
||||||
---@param fn fun(modname:string, modpath:string)
|
---@param fn fun(modname:string, modpath:string)
|
||||||
---@param modname? string
|
---@param modname? string
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue