fix(git): follow symlinks when resolving a buffer's repo
This commit is contained in:
+1
-1
@@ -175,7 +175,7 @@ end
|
||||
|
||||
---@param args string[]
|
||||
function M.run(args)
|
||||
local _, worktree = repo.resolve_cwd()
|
||||
local _, worktree = repo.current_repo()
|
||||
if not worktree then
|
||||
util.warning("not in a git repository")
|
||||
return
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ local M = {}
|
||||
---@param opts { amend: boolean? }?
|
||||
function M.commit(opts)
|
||||
local amend = opts and opts.amend or false
|
||||
local _, worktree = repo.resolve_cwd()
|
||||
local _, worktree = repo.current_repo()
|
||||
if not worktree then
|
||||
util.warning("not in a git repository")
|
||||
return
|
||||
|
||||
+3
-6
@@ -62,7 +62,7 @@ end
|
||||
---@param buf integer
|
||||
---@param rev ow.Git.Revision
|
||||
local function uri_split(opts, buf, rev)
|
||||
local worktree = vim.b[buf].git_worktree or select(2, repo.resolve_cwd())
|
||||
local worktree = vim.b[buf].git_worktree or select(2, repo.current_repo())
|
||||
if not worktree then
|
||||
util.warning("git URI buffer has no worktree")
|
||||
return
|
||||
@@ -154,16 +154,13 @@ function M.split(opts)
|
||||
util.warning("cannot diff this buffer (not a worktree file)")
|
||||
return
|
||||
end
|
||||
local _, worktree = repo.resolve(cur_path)
|
||||
local _, worktree, cur_path = repo.resolve(cur_path)
|
||||
if not worktree then
|
||||
util.warning("not in a git repository")
|
||||
return
|
||||
end
|
||||
---@cast cur_path -nil
|
||||
local rel = vim.fs.relpath(worktree, cur_path)
|
||||
if not rel then
|
||||
util.warning("file is outside the worktree")
|
||||
return
|
||||
end
|
||||
|
||||
local rev
|
||||
if not opts.rev then
|
||||
|
||||
+1
-1
@@ -92,7 +92,7 @@ M.opt_parsers = {
|
||||
---@param opts ow.Git.LogOpts?
|
||||
function M.open(opts)
|
||||
opts = opts or {}
|
||||
local _, worktree = repo.resolve_cwd()
|
||||
local _, worktree = repo.current_repo()
|
||||
if not worktree then
|
||||
util.warning("not in a git repository")
|
||||
return
|
||||
|
||||
+1
-1
@@ -149,7 +149,7 @@ function M.read_uri(buf)
|
||||
end
|
||||
local rev_str = rev:format()
|
||||
|
||||
local worktree = vim.b[buf].git_worktree or select(2, repo.resolve_cwd())
|
||||
local worktree = vim.b[buf].git_worktree or select(2, repo.current_repo())
|
||||
if not worktree then
|
||||
util.error("git BufReadCmd %s: cannot resolve worktree", name)
|
||||
return
|
||||
|
||||
+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
|
||||
|
||||
+3
-2
@@ -837,10 +837,11 @@ local function open(worktree)
|
||||
return
|
||||
end
|
||||
|
||||
local gitdir = repo.resolve(worktree)
|
||||
local gitdir, worktree = repo.resolve(worktree)
|
||||
if not gitdir then
|
||||
return
|
||||
end
|
||||
---@cast worktree -nil
|
||||
|
||||
local previous_win = vim.api.nvim_get_current_win()
|
||||
local bufnr, win = util.new_scratch({ split = "left" })
|
||||
@@ -915,7 +916,7 @@ function M.toggle()
|
||||
vim.api.nvim_win_close(sidebar_win, false)
|
||||
return
|
||||
end
|
||||
local _, worktree = repo.resolve_cwd()
|
||||
local _, worktree = repo.current_repo()
|
||||
if not worktree then
|
||||
util.warning("not in a git repository")
|
||||
return
|
||||
|
||||
+2
-1
@@ -94,7 +94,8 @@ local function do_refresh(r)
|
||||
if not vim.api.nvim_buf_is_valid(buf) then
|
||||
r.buffers[buf] = nil
|
||||
else
|
||||
local status = statuses[vim.api.nvim_buf_get_name(buf)]
|
||||
local status =
|
||||
statuses[vim.fn.resolve(vim.api.nvim_buf_get_name(buf))]
|
||||
if vim.b[buf].git_status ~= status then
|
||||
vim.b[buf].git_status = status
|
||||
dirty = true
|
||||
|
||||
Reference in New Issue
Block a user