summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorSimon Hauser <Simon-Hauser@outlook.de>2021-10-24 08:30:31 +0200
committerGitHub <noreply@github.com>2021-10-24 08:30:31 +0200
commitf31ef362931907bbdd3b46cb880b34493c2d1882 (patch)
tree375fbc3e2f32f05fc6ce1db7d32d4b94ea9b6d4c /lua
parent09b0d87b9f99d37c3e4b64be20389f6797898cf5 (diff)
fix: opts.git_command for files, commits, bcommits (#1374)
Diffstat (limited to 'lua')
-rw-r--r--lua/telescope/builtin/git.lua43
-rw-r--r--lua/telescope/builtin/init.lua3
2 files changed, 17 insertions, 29 deletions
diff --git a/lua/telescope/builtin/git.lua b/lua/telescope/builtin/git.lua
index 0302c7d..7bc88cd 100644
--- a/lua/telescope/builtin/git.lua
+++ b/lua/telescope/builtin/git.lua
@@ -22,16 +22,14 @@ git.files = function(opts)
-- By creating the entry maker after the cwd options,
-- we ensure the maker uses the cwd options when being created.
- opts.entry_maker = opts.entry_maker or make_entry.gen_from_file(opts)
+ opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_file(opts))
+ local git_command = vim.F.if_nil(opts.git_command, { "git", "ls-files", "--exclude-standard", "--cached" })
pickers.new(opts, {
prompt_title = "Git Files",
finder = finders.new_oneshot_job(
vim.tbl_flatten {
- "git",
- "ls-files",
- "--exclude-standard",
- "--cached",
+ git_command,
show_untracked and "--others" or nil,
recurse_submodules and "--recurse-submodules" or nil,
},
@@ -43,22 +41,12 @@ git.files = function(opts)
end
git.commits = function(opts)
- opts.entry_maker = opts.entry_maker or make_entry.gen_from_git_commits(opts)
+ opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_git_commits(opts))
+ local git_command = vim.F.if_nil(opts.git_command, { "git", "log", "--pretty=oneline", "--abbrev-commit", "--", "." })
pickers.new(opts, {
prompt_title = "Git Commits",
-
- finder = finders.new_oneshot_job(
- vim.tbl_flatten {
- "git",
- "log",
- "--pretty=oneline",
- "--abbrev-commit",
- "--",
- ".",
- },
- opts
- ),
+ finder = finders.new_oneshot_job(git_command, opts),
previewer = {
previewers.git_commit_diff_to_parent.new(opts),
previewers.git_commit_diff_to_head.new(opts),
@@ -80,7 +68,7 @@ git.commits = function(opts)
end
git.stash = function(opts)
- opts.entry_maker = opts.entry_maker or make_entry.gen_from_git_stash()
+ opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_git_stash())
pickers.new(opts, {
prompt_title = "Git Stash",
@@ -108,19 +96,16 @@ local get_current_buf_line = function(winnr)
end
git.bcommits = function(opts)
- opts.current_line = not opts.current_file and get_current_buf_line(0) or nil
- opts.current_file = opts.current_file or vim.fn.expand "%:p"
-
- opts.entry_maker = opts.entry_maker or make_entry.gen_from_git_commits(opts)
+ opts.current_line = (opts.current_file == nil) and get_current_buf_line(0) or nil
+ opts.current_file = vim.F.if_nil(opts.current_file, vim.fn.expand "%:p")
+ opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_git_commits(opts))
+ local git_command = vim.F.if_nil(opts.git_command, { "git", "log", "--pretty=oneline", "--abbrev-commit" })
pickers.new(opts, {
prompt_title = "Git BCommits",
finder = finders.new_oneshot_job(
vim.tbl_flatten {
- "git",
- "log",
- "--pretty=oneline",
- "--abbrev-commit",
+ git_command,
opts.current_file,
},
opts
@@ -326,7 +311,7 @@ git.status = function(opts)
return finders.new_table {
results = output,
- entry_maker = opts.entry_maker or make_entry.gen_from_git_status(opts),
+ entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_git_status(opts)),
}
end
@@ -380,7 +365,7 @@ end
local function apply_checks(mod)
for k, v in pairs(mod) do
mod[k] = function(opts)
- opts = opts or {}
+ opts = vim.F.if_nil(opts, {})
set_opts_cwd(opts)
v(opts)
diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua
index dd7ac48..614767a 100644
--- a/lua/telescope/builtin/init.lua
+++ b/lua/telescope/builtin/init.lua
@@ -146,6 +146,7 @@ builtin.current_buffer_tags = require_on_exported_call("telescope.builtin.files"
---@field use_git_root boolean: if we should use git root as cwd or the cwd (important for submodule) (default: true)
---@field show_untracked boolean: if true, adds `--others` flag to command and shows untracked files (default: true)
---@field recurse_submodules boolean: if true, adds the `--recurse-submodules` flag to command (default: false)
+---@field git_command table: command that will be exectued. {"git","ls-files","--exclude-standard","--cached"}
builtin.git_files = require_on_exported_call("telescope.builtin.git").files
--- Lists commits for current directory with diff preview
@@ -157,6 +158,7 @@ builtin.git_files = require_on_exported_call("telescope.builtin.git").files
---@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 git_command table: command that will be exectued. {"git","log","--pretty=oneline","--abbrev-commit","--","."}
builtin.git_commits = require_on_exported_call("telescope.builtin.git").commits
--- Lists commits for current buffer with diff preview
@@ -169,6 +171,7 @@ builtin.git_commits = require_on_exported_call("telescope.builtin.git").commits
---@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 current_file string: specify the current file that should be used for bcommits (default: current buffer)
+---@field git_command table: command that will be exectued. {"git","log","--pretty=oneline","--abbrev-commit"}
builtin.git_bcommits = require_on_exported_call("telescope.builtin.git").bcommits
--- List branches for current directory, with output from `git log --oneline` shown in the preview window