feat(git/cmd): improved completion for :G

This commit is contained in:
2026-05-07 15:28:26 +02:00
parent 1b0315750d
commit 2abd1d653d
3 changed files with 381 additions and 34 deletions
+39 -2
View File
@@ -179,8 +179,45 @@ function Repo:list_refs()
if not out then
return {}
end
local refs = util.split_lines(out)
table.insert(refs, 1, "HEAD")
return util.split_lines(out)
end
local PSEUDO_REFS = {
"HEAD",
"FETCH_HEAD",
"ORIG_HEAD",
"MERGE_HEAD",
"REBASE_HEAD",
"CHERRY_PICK_HEAD",
"REVERT_HEAD",
}
---@return string[]
function Repo:list_pseudo_refs()
local refs = {}
for _, name in ipairs(PSEUDO_REFS) do
if name == "HEAD" or vim.uv.fs_stat(self.gitdir .. "/" .. name) then
table.insert(refs, name)
end
end
return refs
end
---@return string[]
function Repo:list_stash_refs()
if not vim.uv.fs_stat(self.gitdir .. "/refs/stash") then
return {}
end
local refs = { "stash" }
local out = util.exec(
{ "git", "stash", "list", "--pretty=format:%gd" },
{ cwd = self.worktree, silent = true }
)
if out then
for _, entry in ipairs(util.split_lines(out)) do
table.insert(refs, entry)
end
end
return refs
end