fix(git): follow symlinks when resolving a buffer's repo
This commit is contained in:
+8
-5
@@ -5,7 +5,9 @@ local M = {}
|
||||
---@param path string
|
||||
---@return string? gitdir
|
||||
---@return string? worktree
|
||||
---@return string? path
|
||||
function M.resolve(path)
|
||||
path = vim.fn.resolve(path)
|
||||
local found = vim.fs.find(".git", { upward = true, path = path })[1]
|
||||
if not found then
|
||||
return nil
|
||||
@@ -16,7 +18,7 @@ function M.resolve(path)
|
||||
return nil
|
||||
end
|
||||
if stat.type == "directory" then
|
||||
return found, worktree
|
||||
return found, worktree, path
|
||||
end
|
||||
local f = io.open(found, "r")
|
||||
if not f then
|
||||
@@ -32,17 +34,18 @@ function M.resolve(path)
|
||||
if not gitdir:match("^/") then
|
||||
gitdir = vim.fs.joinpath(worktree, gitdir)
|
||||
end
|
||||
return vim.fs.normalize(gitdir), worktree
|
||||
return vim.fs.normalize(gitdir), worktree, path
|
||||
end
|
||||
|
||||
---@return string? gitdir
|
||||
---@return string? worktree
|
||||
function M.resolve_cwd()
|
||||
function M.current_repo()
|
||||
local path = vim.api.nvim_buf_get_name(0)
|
||||
if path == "" or path:match("^%a+://") then
|
||||
path = vim.fn.getcwd()
|
||||
end
|
||||
return M.resolve(path)
|
||||
local gitdir, worktree, _ = M.resolve(path)
|
||||
return gitdir, worktree
|
||||
end
|
||||
|
||||
---@param path string
|
||||
@@ -94,7 +97,7 @@ end
|
||||
---@param arg_lead string
|
||||
---@return string[]
|
||||
function M.complete_rev(arg_lead)
|
||||
local _, worktree = M.resolve_cwd()
|
||||
local _, worktree = M.current_repo()
|
||||
if not worktree then
|
||||
return {}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user