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[]
|
---@param args string[]
|
||||||
function M.run(args)
|
function M.run(args)
|
||||||
local _, worktree = repo.resolve_cwd()
|
local _, worktree = repo.current_repo()
|
||||||
if not worktree then
|
if not worktree then
|
||||||
util.warning("not in a git repository")
|
util.warning("not in a git repository")
|
||||||
return
|
return
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@ local M = {}
|
|||||||
---@param opts { amend: boolean? }?
|
---@param opts { amend: boolean? }?
|
||||||
function M.commit(opts)
|
function M.commit(opts)
|
||||||
local amend = opts and opts.amend or false
|
local amend = opts and opts.amend or false
|
||||||
local _, worktree = repo.resolve_cwd()
|
local _, worktree = repo.current_repo()
|
||||||
if not worktree then
|
if not worktree then
|
||||||
util.warning("not in a git repository")
|
util.warning("not in a git repository")
|
||||||
return
|
return
|
||||||
|
|||||||
+3
-6
@@ -62,7 +62,7 @@ end
|
|||||||
---@param buf integer
|
---@param buf integer
|
||||||
---@param rev ow.Git.Revision
|
---@param rev ow.Git.Revision
|
||||||
local function uri_split(opts, buf, rev)
|
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
|
if not worktree then
|
||||||
util.warning("git URI buffer has no worktree")
|
util.warning("git URI buffer has no worktree")
|
||||||
return
|
return
|
||||||
@@ -154,16 +154,13 @@ function M.split(opts)
|
|||||||
util.warning("cannot diff this buffer (not a worktree file)")
|
util.warning("cannot diff this buffer (not a worktree file)")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local _, worktree = repo.resolve(cur_path)
|
local _, worktree, cur_path = repo.resolve(cur_path)
|
||||||
if not worktree then
|
if not worktree then
|
||||||
util.warning("not in a git repository")
|
util.warning("not in a git repository")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
---@cast cur_path -nil
|
||||||
local rel = vim.fs.relpath(worktree, cur_path)
|
local rel = vim.fs.relpath(worktree, cur_path)
|
||||||
if not rel then
|
|
||||||
util.warning("file is outside the worktree")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local rev
|
local rev
|
||||||
if not opts.rev then
|
if not opts.rev then
|
||||||
|
|||||||
+1
-1
@@ -92,7 +92,7 @@ M.opt_parsers = {
|
|||||||
---@param opts ow.Git.LogOpts?
|
---@param opts ow.Git.LogOpts?
|
||||||
function M.open(opts)
|
function M.open(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
local _, worktree = repo.resolve_cwd()
|
local _, worktree = repo.current_repo()
|
||||||
if not worktree then
|
if not worktree then
|
||||||
util.warning("not in a git repository")
|
util.warning("not in a git repository")
|
||||||
return
|
return
|
||||||
|
|||||||
+1
-1
@@ -149,7 +149,7 @@ function M.read_uri(buf)
|
|||||||
end
|
end
|
||||||
local rev_str = rev:format()
|
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
|
if not worktree then
|
||||||
util.error("git BufReadCmd %s: cannot resolve worktree", name)
|
util.error("git BufReadCmd %s: cannot resolve worktree", name)
|
||||||
return
|
return
|
||||||
|
|||||||
+8
-5
@@ -5,7 +5,9 @@ local M = {}
|
|||||||
---@param path string
|
---@param path string
|
||||||
---@return string? gitdir
|
---@return string? gitdir
|
||||||
---@return string? worktree
|
---@return string? worktree
|
||||||
|
---@return string? path
|
||||||
function M.resolve(path)
|
function M.resolve(path)
|
||||||
|
path = vim.fn.resolve(path)
|
||||||
local found = vim.fs.find(".git", { upward = true, path = path })[1]
|
local found = vim.fs.find(".git", { upward = true, path = path })[1]
|
||||||
if not found then
|
if not found then
|
||||||
return nil
|
return nil
|
||||||
@@ -16,7 +18,7 @@ function M.resolve(path)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
if stat.type == "directory" then
|
if stat.type == "directory" then
|
||||||
return found, worktree
|
return found, worktree, path
|
||||||
end
|
end
|
||||||
local f = io.open(found, "r")
|
local f = io.open(found, "r")
|
||||||
if not f then
|
if not f then
|
||||||
@@ -32,17 +34,18 @@ function M.resolve(path)
|
|||||||
if not gitdir:match("^/") then
|
if not gitdir:match("^/") then
|
||||||
gitdir = vim.fs.joinpath(worktree, gitdir)
|
gitdir = vim.fs.joinpath(worktree, gitdir)
|
||||||
end
|
end
|
||||||
return vim.fs.normalize(gitdir), worktree
|
return vim.fs.normalize(gitdir), worktree, path
|
||||||
end
|
end
|
||||||
|
|
||||||
---@return string? gitdir
|
---@return string? gitdir
|
||||||
---@return string? worktree
|
---@return string? worktree
|
||||||
function M.resolve_cwd()
|
function M.current_repo()
|
||||||
local path = vim.api.nvim_buf_get_name(0)
|
local path = vim.api.nvim_buf_get_name(0)
|
||||||
if path == "" or path:match("^%a+://") then
|
if path == "" or path:match("^%a+://") then
|
||||||
path = vim.fn.getcwd()
|
path = vim.fn.getcwd()
|
||||||
end
|
end
|
||||||
return M.resolve(path)
|
local gitdir, worktree, _ = M.resolve(path)
|
||||||
|
return gitdir, worktree
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param path string
|
---@param path string
|
||||||
@@ -94,7 +97,7 @@ end
|
|||||||
---@param arg_lead string
|
---@param arg_lead string
|
||||||
---@return string[]
|
---@return string[]
|
||||||
function M.complete_rev(arg_lead)
|
function M.complete_rev(arg_lead)
|
||||||
local _, worktree = M.resolve_cwd()
|
local _, worktree = M.current_repo()
|
||||||
if not worktree then
|
if not worktree then
|
||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
|
|||||||
+3
-2
@@ -837,10 +837,11 @@ local function open(worktree)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local gitdir = repo.resolve(worktree)
|
local gitdir, worktree = repo.resolve(worktree)
|
||||||
if not gitdir then
|
if not gitdir then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
---@cast worktree -nil
|
||||||
|
|
||||||
local previous_win = vim.api.nvim_get_current_win()
|
local previous_win = vim.api.nvim_get_current_win()
|
||||||
local bufnr, win = util.new_scratch({ split = "left" })
|
local bufnr, win = util.new_scratch({ split = "left" })
|
||||||
@@ -915,7 +916,7 @@ function M.toggle()
|
|||||||
vim.api.nvim_win_close(sidebar_win, false)
|
vim.api.nvim_win_close(sidebar_win, false)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local _, worktree = repo.resolve_cwd()
|
local _, worktree = repo.current_repo()
|
||||||
if not worktree then
|
if not worktree then
|
||||||
util.warning("not in a git repository")
|
util.warning("not in a git repository")
|
||||||
return
|
return
|
||||||
|
|||||||
+2
-1
@@ -94,7 +94,8 @@ local function do_refresh(r)
|
|||||||
if not vim.api.nvim_buf_is_valid(buf) then
|
if not vim.api.nvim_buf_is_valid(buf) then
|
||||||
r.buffers[buf] = nil
|
r.buffers[buf] = nil
|
||||||
else
|
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
|
if vim.b[buf].git_status ~= status then
|
||||||
vim.b[buf].git_status = status
|
vim.b[buf].git_status = status
|
||||||
dirty = true
|
dirty = true
|
||||||
|
|||||||
Reference in New Issue
Block a user