summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Taylor <mstaveleytaylor@gmail.com>2023-01-11 06:00:44 -0800
committerGitHub <noreply@github.com>2023-01-11 15:00:44 +0100
commit1ba7278cf08da8048e7f589ef6b65a39fd3e4dbf (patch)
treeec2a4a0fb07698b5345012d79c7d44b4d7737209
parente8c01bab917537ba4f54193c29b77bf4a04584d3 (diff)
feat(pickers): add opt.show_remote_tracking_branches to git_branches (#2314)
-rw-r--r--doc/telescope.txt15
-rw-r--r--lua/telescope/builtin/__git.lua7
-rw-r--r--lua/telescope/builtin/init.lua1
3 files changed, 18 insertions, 5 deletions
diff --git a/doc/telescope.txt b/doc/telescope.txt
index 04ce52f..4069722 100644
--- a/doc/telescope.txt
+++ b/doc/telescope.txt
@@ -1028,10 +1028,17 @@ builtin.git_branches({opts}) *telescope.builtin.git_branches()*
{opts} (table) options to pass to the picker
Options: ~
- {cwd} (string) specify the path of the repo
- {use_git_root} (boolean) if we should use git root as cwd or the cwd
- (important for submodule) (default: true)
- {pattern} (string) specify the pattern to match all refs
+ {cwd} (string) specify the path of the
+ repo
+ {use_git_root} (boolean) if we should use git root
+ as cwd or the cwd
+ (important for submodule)
+ (default: true)
+ {show_remote_tracking_branches} (boolean) show remote tracking
+ branches like origin/main
+ (default: true)
+ {pattern} (string) specify the pattern to
+ match all refs
builtin.git_status({opts}) *telescope.builtin.git_status()*
diff --git a/lua/telescope/builtin/__git.lua b/lua/telescope/builtin/__git.lua
index 737ad26..866934f 100644
--- a/lua/telescope/builtin/__git.lua
+++ b/lua/telescope/builtin/__git.lua
@@ -203,6 +203,7 @@ git.branches = function(opts)
{ "git", "for-each-ref", "--perl", "--format", format, "--sort", "-authordate", opts.pattern },
opts.cwd
)
+ local show_remote_tracking_branches = vim.F.if_nil(opts.show_remote_tracking_branches, true)
local results = {}
local widths = {
@@ -225,7 +226,11 @@ git.branches = function(opts)
}
local prefix
if vim.startswith(entry.refname, "refs/remotes/") then
- prefix = "refs/remotes/"
+ if show_remote_tracking_branches then
+ prefix = "refs/remotes/"
+ else
+ return
+ end
elseif vim.startswith(entry.refname, "refs/heads/") then
prefix = "refs/heads/"
else
diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua
index eef35b6..0f4c998 100644
--- a/lua/telescope/builtin/init.lua
+++ b/lua/telescope/builtin/init.lua
@@ -172,6 +172,7 @@ builtin.git_bcommits = require_on_exported_call("telescope.builtin.__git").bcomm
---@param opts table: options to pass to the picker
---@field cwd string: specify the path of the repo
---@field use_git_root boolean: if we should use git root as cwd or the cwd (important for submodule) (default: true)
+---@field show_remote_tracking_branches boolean: show remote tracking branches like origin/main (default: true)
---@field pattern string: specify the pattern to match all refs
builtin.git_branches = require_on_exported_call("telescope.builtin.__git").branches