feat(git): rev completion for :Gdiffsplit family
This commit is contained in:
@@ -111,6 +111,41 @@ function M.head(path)
|
||||
return nil
|
||||
end
|
||||
|
||||
---@param worktree string
|
||||
---@return string[]
|
||||
function M.list_refs(worktree)
|
||||
local out = util.exec({
|
||||
"git",
|
||||
"for-each-ref",
|
||||
"--format=%(refname:short)",
|
||||
"refs/heads",
|
||||
"refs/tags",
|
||||
"refs/remotes",
|
||||
}, { cwd = worktree, silent = true })
|
||||
if not out then
|
||||
return {}
|
||||
end
|
||||
local refs = util.split_lines(out)
|
||||
table.insert(refs, 1, "HEAD")
|
||||
return refs
|
||||
end
|
||||
|
||||
---@param arg_lead string
|
||||
---@return string[]
|
||||
function M.complete_rev(arg_lead)
|
||||
local _, worktree = M.resolve_cwd()
|
||||
if not worktree then
|
||||
return {}
|
||||
end
|
||||
local matches = {}
|
||||
for _, ref in ipairs(M.list_refs(worktree)) do
|
||||
if ref:sub(1, #arg_lead) == arg_lead then
|
||||
table.insert(matches, ref)
|
||||
end
|
||||
end
|
||||
return matches
|
||||
end
|
||||
|
||||
---@param worktree string
|
||||
---@param rev string
|
||||
---@param short boolean
|
||||
|
||||
Reference in New Issue
Block a user