From f31ef362931907bbdd3b46cb880b34493c2d1882 Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Sun, 24 Oct 2021 08:30:31 +0200 Subject: [PATCH] fix: opts.git_command for files, commits, bcommits (#1374) --- doc/telescope.txt | 6 +++++ lua/telescope/builtin/git.lua | 43 +++++++++++----------------------- lua/telescope/builtin/init.lua | 3 +++ 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index 1bce979..3e1c0c4 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -848,6 +848,8 @@ builtin.git_files({opts}) *builtin.git_files()* {recurse_submodules} (boolean) if true, adds the `--recurse-submodules` flag to command (default: false) + {git_command} (table) command that will be exectued. + {"git","ls-files","--exclude-standard","--cached"} builtin.git_commits({opts}) *builtin.git_commits()* @@ -866,6 +868,8 @@ builtin.git_commits({opts}) *builtin.git_commits()* {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) + {git_command} (table) command that will be exectued. + {"git","log","--pretty=oneline","--abbrev-commit","--","."} builtin.git_bcommits({opts}) *builtin.git_bcommits()* @@ -886,6 +890,8 @@ builtin.git_bcommits({opts}) *builtin.git_bcommits()* (important for submodule) (default: true) {current_file} (string) specify the current file that should be used for bcommits (default: current buffer) + {git_command} (table) command that will be exectued. + {"git","log","--pretty=oneline","--abbrev-commit"} builtin.git_branches({opts}) *builtin.git_branches()* 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