fix: opts.git_command for files, commits, bcommits (#1374)

This commit is contained in:
Simon Hauser
2021-10-24 08:30:31 +02:00
committed by GitHub
parent 09b0d87b9f
commit f31ef36293
3 changed files with 23 additions and 29 deletions

View File

@@ -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)

View File

@@ -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