feat(picker): added git_branches picker. Closes #614

This commit is contained in:
Folke Lemaitre 2025-01-19 16:24:35 +01:00
parent 903431903b
commit 8563dfce68
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
8 changed files with 196 additions and 7 deletions

View file

@ -86,6 +86,7 @@ end
---@type snacks.picker.finder
function M.status(opts)
local args = {
"--no-pager",
"status",
"-uall",
"--porcelain=v1",
@ -154,4 +155,26 @@ function M.diff(opts)
end
end
---@param opts snacks.picker.Config
---@type snacks.picker.finder
function M.branches(opts)
local args = { "--no-pager", "branch", "--no-color", "-vvl" }
local cwd = vim.fs.normalize(opts and opts.cwd or uv.cwd() or ".") or nil
cwd = Snacks.git.get_root(cwd)
return require("snacks.picker.source.proc").proc(vim.tbl_deep_extend("force", {
cwd = cwd,
cmd = "git",
args = args,
---@param item snacks.picker.finder.Item
transform = function(item)
local status, branch, commit, msg = item.text:match("^(.)%s(%S+)%s+([a-zA-Z0-9]+)%s*(.*)$")
item.cwd = cwd
item.current = status == "*"
item.branch = branch
item.commit = commit
item.msg = msg
end,
}, opts or {}))
end
return M