From 6db4274a36fc83d934eb2f415e9f6653f31d5103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E7=8E=AE=20=28Jade=20Lin=29?= Date: Tue, 1 Jul 2025 21:54:25 +0800 Subject: [PATCH 1/2] 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. --- lua/lazy/core/util.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lua/lazy/core/util.lua b/lua/lazy/core/util.lua index 83e8a92e..d60fb848 100644 --- a/lua/lazy/core/util.lua +++ b/lua/lazy/core/util.lua @@ -228,6 +228,17 @@ function M.walk(path, fn) 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 fn fun(modname:string, modpath:string) ---@param modname? string From fc85da9a7daf1d1429434f4cd9999bf1599fefef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E7=8E=AE=20=28Jade=20Lin=29?= Date: Tue, 1 Jul 2025 22:34:23 +0800 Subject: [PATCH 2/2] fix(plugin): update plugin configuration --- lua/lazy/core/plugin.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lua/lazy/core/plugin.lua b/lua/lazy/core/plugin.lua index 37d1a8f4..5c39e4fd 100644 --- a/lua/lazy/core/plugin.lua +++ b/lua/lazy/core/plugin.lua @@ -315,6 +315,18 @@ function M.find_local_spec() end end +function M.find_actual_origin_spec() + local info = debug.getinfo(2, "S") + local current_file = info.source:sub(2) -- remove the leading '@' + local current_dir = vim.fn.fnamemodify(current_file, ":h") + local git_root = Util.find_git_root(current_dir) + local Git = require("lazy.manage.git") + + return { + url = Git.get_origin(git_root), + } +end + function M.load() M.loading = true -- load specs @@ -326,7 +338,7 @@ function M.load() vim.deepcopy(Config.options.spec), } specs[#specs + 1] = M.find_local_spec() - specs[#specs + 1] = { "folke/lazy.nvim" } + specs[#specs + 1] = M.find_actual_origin_spec() Config.spec:parse(specs)