mirror of
https://github.com/folke/snacks.nvim
synced 2025-12-23 08:47:57 +00:00
feat(picker.git): added all option to also list remote branched for git_branches. Closes #1465
This commit is contained in:
parent
e591715b03
commit
3d695ab7d0
3 changed files with 15 additions and 3 deletions
|
|
@ -346,12 +346,16 @@ end
|
|||
function M.git_checkout(picker, item)
|
||||
picker:close()
|
||||
if item then
|
||||
local what = item.branch or item.commit
|
||||
local what = item.branch or item.commit --[[@as string?]]
|
||||
if not what then
|
||||
Snacks.notify.warn("No branch or commit found", { title = "Snacks Picker" })
|
||||
return
|
||||
end
|
||||
local cmd = { "git", "checkout", what }
|
||||
local remote_branch = what:match("^remotes/[^/]+/(.+)$")
|
||||
if remote_branch then
|
||||
cmd = { "git", "checkout", "-b", remote_branch, what }
|
||||
end
|
||||
if item.file then
|
||||
vim.list_extend(cmd, { "--", item.file })
|
||||
end
|
||||
|
|
|
|||
|
|
@ -210,8 +210,10 @@ M.files = {
|
|||
---@class snacks.picker.git.Config: snacks.picker.Config
|
||||
---@field args? string[] additional arguments to pass to `git ls-files`
|
||||
|
||||
---@type snacks.picker.git.Config
|
||||
---@class snacks.picker.git.branches.Config: snacks.picker.git.Config
|
||||
---@field all? boolean show all branches, including remote
|
||||
M.git_branches = {
|
||||
all = false,
|
||||
finder = "git_branches",
|
||||
format = "git_branch",
|
||||
preview = "git_log",
|
||||
|
|
|
|||
|
|
@ -262,10 +262,13 @@ function M.diff(opts, ctx)
|
|||
end
|
||||
end
|
||||
|
||||
---@param opts snacks.picker.git.Config
|
||||
---@param opts snacks.picker.git.branches.Config
|
||||
---@type snacks.picker.finder
|
||||
function M.branches(opts, ctx)
|
||||
local args = git_args(opts.args, "--no-pager", "branch", "--no-color", "-vvl")
|
||||
if opts.all then
|
||||
table.insert(args, "--all")
|
||||
end
|
||||
local cwd = svim.fs.normalize(opts and opts.cwd or uv.cwd() or ".") or nil
|
||||
cwd = Snacks.git.get_root(cwd)
|
||||
|
||||
|
|
@ -287,6 +290,9 @@ function M.branches(opts, ctx)
|
|||
---@param item snacks.picker.finder.Item
|
||||
transform = function(item)
|
||||
item.cwd = cwd
|
||||
if item.text:find("HEAD.*%->") then
|
||||
return false
|
||||
end
|
||||
for p, pattern in ipairs(patterns) do
|
||||
local status, branch, commit, msg = item.text:match(pattern)
|
||||
if status then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue