feat(git): rev completion for :Gdiffsplit family

This commit is contained in:
2026-04-30 17:20:12 +02:00
parent 7fa05d4895
commit 9f44c9de40
2 changed files with 53 additions and 15 deletions
+35
View File
@@ -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