From 4aa6a9a7cc823054079edaa190577c6b5ef9e038 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Wed, 22 Feb 2023 02:49:47 -0500 Subject: [PATCH 01/12] Filter bcommits by selection in visual mode --- README.md | 2 +- doc/telescope.txt | 1 + lua/telescope/builtin/__git.lua | 35 ++++++++++++++++++++++++++------- lua/telescope/builtin/init.lua | 1 + 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9077980019..2f16eeb277 100644 --- a/README.md +++ b/README.md @@ -360,7 +360,7 @@ Built-in functions. Ready to be bound to any key you like. | Functions | Description | |-------------------------------------|------------------------------------------------------------------------------------------------------------| | `builtin.git_commits` | Lists git commits with diff preview, checkout action ``, reset mixed `m`, reset soft `s` and reset hard `h` | -| `builtin.git_bcommits` | Lists buffer's git commits with diff preview and checks them out on `` | +| `builtin.git_bcommits` | Lists buffer's git commits with diff preview and checks them out on ``. In visual mode, lists commits for selected lines | | `builtin.git_branches` | Lists all branches with log preview, checkout action ``, track action ``, rebase action``, create action ``, switch action ``, delete action `` and merge action `` | | `builtin.git_status` | Lists current changes per file with diff preview and add action. (Multi-selection still WIP) | | `builtin.git_stash` | Lists stash items in current repository with ability to apply them on `` | diff --git a/doc/telescope.txt b/doc/telescope.txt index 18dc03b2aa..31abee7d6d 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -1030,6 +1030,7 @@ builtin.git_commits({opts}) *telescope.builtin.git_commits()* builtin.git_bcommits({opts}) *telescope.builtin.git_bcommits()* Lists commits for current buffer with diff preview + In visual mode, lists commits for the selected lines - Default keymaps or your overridden `select_` keys: - ``: checks out the currently selected commit - ``: opens a diff in a vertical split diff --git a/lua/telescope/builtin/__git.lua b/lua/telescope/builtin/__git.lua index 380570a40e..6bd9919ae9 100644 --- a/lua/telescope/builtin/__git.lua +++ b/lua/telescope/builtin/__git.lua @@ -116,17 +116,38 @@ git.bcommits = function(opts) opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_git_commits(opts)) opts.git_command = vim.F.if_nil(opts.git_command, git_command({ "log", "--pretty=oneline", "--abbrev-commit", "--follow" }, opts)) + local visual = string.find(vim.fn.mode(), "[vV]") ~= nil + + if visual == true then + -- filter lines by visual selection range + local line_number_start = vim.fn.line "v" + local line_number_end = vim.fn.line "." + local line_range = + string.format("%d,%d:%s", line_number_start, line_number_end, Path:new(opts.current_file):make_relative(opts.cwd)) + -- remove incompatible arguments from git_command + local visual_git_command = {} + for _, v in ipairs(git_command) do + if v ~= "--follow" then + table.insert(visual_git_command, v) + end + end + git_command = vim.tbl_flatten { + visual_git_command, + "--no-patch", + "-L", + line_range, + } + else + git_command = vim.tbl_flatten { + git_command, + opts.current_file, + } + end pickers .new(opts, { prompt_title = "Git BCommits", - finder = finders.new_oneshot_job( - vim.tbl_flatten { - opts.git_command, - opts.current_file, - }, - opts - ), + finder = finders.new_oneshot_job(opts.git_command, opts), previewer = { previewers.git_commit_diff_to_parent.new(opts), previewers.git_commit_diff_to_head.new(opts), diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index d2ded8c176..1d328f7993 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -159,6 +159,7 @@ builtin.git_files = require_on_exported_call("telescope.builtin.__git").files builtin.git_commits = require_on_exported_call("telescope.builtin.__git").commits --- Lists commits for current buffer with diff preview +--- In visual mode, lists commits for the selected lines --- - Default keymaps or your overridden `select_` keys: --- - ``: checks out the currently selected commit --- - ``: opens a diff in a vertical split From 343f3f3d66d3608f8eb3b9b8b45f14e92151b435 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Tue, 21 Mar 2023 17:33:27 -0400 Subject: [PATCH 02/12] Split bcommits_range into new picker --- README.md | 3 +- doc/telescope.txt | 27 ++++++- lua/telescope/builtin/__git.lua | 124 +++++++++++++++++++++++++------- lua/telescope/builtin/init.lua | 17 ++++- 4 files changed, 142 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 2f16eeb277..0db363e134 100644 --- a/README.md +++ b/README.md @@ -360,7 +360,8 @@ Built-in functions. Ready to be bound to any key you like. | Functions | Description | |-------------------------------------|------------------------------------------------------------------------------------------------------------| | `builtin.git_commits` | Lists git commits with diff preview, checkout action ``, reset mixed `m`, reset soft `s` and reset hard `h` | -| `builtin.git_bcommits` | Lists buffer's git commits with diff preview and checks them out on ``. In visual mode, lists commits for selected lines | +| `builtin.git_bcommits` | Lists buffer's git commits with diff preview and checks them out on `` | +| `builtin.git_bcommits_range` | Lists buffer's git commits in a range of lines. Use options `start` and `end` to specify the range. In visual mode, lists commits for the selected lines | | `builtin.git_branches` | Lists all branches with log preview, checkout action ``, track action ``, rebase action``, create action ``, switch action ``, delete action `` and merge action `` | | `builtin.git_status` | Lists current changes per file with diff preview and add action. (Multi-selection still WIP) | | `builtin.git_stash` | Lists stash items in current repository with ability to apply them on `` | diff --git a/doc/telescope.txt b/doc/telescope.txt index 31abee7d6d..d4f92d8c88 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -1030,7 +1030,6 @@ builtin.git_commits({opts}) *telescope.builtin.git_commits()* builtin.git_bcommits({opts}) *telescope.builtin.git_bcommits()* Lists commits for current buffer with diff preview - In visual mode, lists commits for the selected lines - Default keymaps or your overridden `select_` keys: - ``: checks out the currently selected commit - ``: opens a diff in a vertical split @@ -1053,6 +1052,32 @@ builtin.git_bcommits({opts}) *telescope.builtin.git_bcommits()* {"git","log","--pretty=oneline","--abbrev-commit"} +builtin.git_bcommits_range({opts}) *telescope.builtin.git_bcommits_range()* + Lists commits for a range of lines in the current buffer with diff preview + In visual mode, lists commits for the selected lines + - Default keymaps or your overridden `select_` keys: + - ``: checks out the currently selected commit + - ``: opens a diff in a vertical split + - ``: opens a diff in a horizontal split + - ``: opens a diff in a new tab + + + Parameters: ~ + {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) + {current_file} (string) specify the current file that should be used + for bcommits (default: current buffer) + {git_command} (table) command that will be executed. + {"git","log","--pretty=oneline","--abbrev-commit","--no-patch","-L"} + {start} (number) the first line in the range + (optional in visual mode) + {stop} (number) the last line in the range + (optional in visual mode) + builtin.git_branches({opts}) *telescope.builtin.git_branches()* List branches for current directory, with output from `git log --oneline` shown in the preview window diff --git a/lua/telescope/builtin/__git.lua b/lua/telescope/builtin/__git.lua index 6bd9919ae9..c454aecdba 100644 --- a/lua/telescope/builtin/__git.lua +++ b/lua/telescope/builtin/__git.lua @@ -116,38 +116,110 @@ git.bcommits = function(opts) opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_git_commits(opts)) opts.git_command = vim.F.if_nil(opts.git_command, git_command({ "log", "--pretty=oneline", "--abbrev-commit", "--follow" }, opts)) + + pickers + .new(opts, { + prompt_title = "Git BCommits", + finder = finders.new_oneshot_job( + vim.tbl_flatten { + opts.git_command, + opts.current_file, + }, + opts + ), + previewer = { + previewers.git_commit_diff_to_parent.new(opts), + previewers.git_commit_diff_to_head.new(opts), + previewers.git_commit_diff_as_was.new(opts), + previewers.git_commit_message.new(opts), + }, + sorter = conf.file_sorter(opts), + attach_mappings = function() + actions.select_default:replace(actions.git_checkout_current_buffer) + local transfrom_file = function() + return opts.current_file and Path:new(opts.current_file):make_relative(opts.cwd) or "" + end + + local get_buffer_of_orig = function(selection) + local value = selection.value .. ":" .. transfrom_file() + local content = utils.get_os_command_output({ "git", "--no-pager", "show", value }, opts.cwd) + + local bufnr = vim.api.nvim_create_buf(false, true) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, content) + vim.api.nvim_buf_set_name(bufnr, "Original") + return bufnr + end + + local vimdiff = function(selection, command) + local ft = vim.bo.filetype + vim.cmd "diffthis" + + local bufnr = get_buffer_of_orig(selection) + vim.cmd(string.format("%s %s", command, bufnr)) + vim.bo.filetype = ft + vim.cmd "diffthis" + + vim.api.nvim_create_autocmd("WinClosed", { + buffer = bufnr, + nested = true, + once = true, + callback = function() + vim.api.nvim_buf_delete(bufnr, { force = true }) + end, + }) + end + + actions.select_vertical:replace(function(prompt_bufnr) + actions.close(prompt_bufnr) + local selection = action_state.get_selected_entry() + vimdiff(selection, "leftabove vert sbuffer") + end) + + actions.select_horizontal:replace(function(prompt_bufnr) + actions.close(prompt_bufnr) + local selection = action_state.get_selected_entry() + vimdiff(selection, "belowright sbuffer") + end) + + actions.select_tab:replace(function(prompt_bufnr) + actions.close(prompt_bufnr) + local selection = action_state.get_selected_entry() + vim.cmd("tabedit " .. transfrom_file()) + vimdiff(selection, "leftabove vert sbuffer") + end) + return true + end, + }) + :find() +end + +git.bcommits_range = function(opts) + opts.current_line = (opts.current_file == nil) and get_current_buf_line(opts.winnr) or nil + opts.current_file = vim.F.if_nil(opts.current_file, vim.api.nvim_buf_get_name(opts.bufnr)) + 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", "--no-patch", "-L" }) local visual = string.find(vim.fn.mode(), "[vV]") ~= nil - if visual == true then - -- filter lines by visual selection range - local line_number_start = vim.fn.line "v" - local line_number_end = vim.fn.line "." - local line_range = - string.format("%d,%d:%s", line_number_start, line_number_end, Path:new(opts.current_file):make_relative(opts.cwd)) - -- remove incompatible arguments from git_command - local visual_git_command = {} - for _, v in ipairs(git_command) do - if v ~= "--follow" then - table.insert(visual_git_command, v) - end - end - git_command = vim.tbl_flatten { - visual_git_command, - "--no-patch", - "-L", - line_range, - } - else - git_command = vim.tbl_flatten { - git_command, - opts.current_file, - } + local line_number_start = opts.start + local line_number_stop = vim.F.if_nil(opts.stop, line_number_start) + if visual then + line_number_start = vim.F.if_nil(line_number_start, vim.fn.line "v") + line_number_stop = vim.F.if_nil(line_number_stop, vim.fn.line ".") end + local line_range = + string.format("%d,%d:%s", line_number_start, line_number_stop, Path:new(opts.current_file):make_relative(opts.cwd)) pickers .new(opts, { - prompt_title = "Git BCommits", - finder = finders.new_oneshot_job(opts.git_command, opts), + prompt_title = "Git BCommits in range", + finder = finders.new_oneshot_job( + vim.tbl_flatten { + git_command, + line_range, + }, + opts + ), previewer = { previewers.git_commit_diff_to_parent.new(opts), previewers.git_commit_diff_to_head.new(opts), diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index 1d328f7993..755612985c 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -159,7 +159,6 @@ builtin.git_files = require_on_exported_call("telescope.builtin.__git").files builtin.git_commits = require_on_exported_call("telescope.builtin.__git").commits --- Lists commits for current buffer with diff preview ---- In visual mode, lists commits for the selected lines --- - Default keymaps or your overridden `select_` keys: --- - ``: checks out the currently selected commit --- - ``: opens a diff in a vertical split @@ -173,6 +172,22 @@ builtin.git_commits = require_on_exported_call("telescope.builtin.__git").commit ---@field git_command table: command that will be executed. {"git","log","--pretty=oneline","--abbrev-commit"} builtin.git_bcommits = require_on_exported_call("telescope.builtin.__git").bcommits +--- Lists commits for a range of lines in the current buffer with diff preview +--- In visual mode, lists commits for the selected lines +--- - Default keymaps or your overridden `select_` keys: +--- - ``: checks out the currently selected commit +--- - ``: opens a diff in a vertical split +--- - ``: opens a diff in a horizontal split +--- - ``: opens a diff in a new tab +---@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 current_file string: specify the current file that should be used for bcommits (default: current buffer) +---@field git_command table: command that will be executed. {"git","log","--pretty=oneline","--abbrev-commit","--no-patch","-L"} +---@field start number: the first line in the range (optional in visual or operator mode) +---@field stop number: the last line in the range (optional in visual or operator mode) +builtin.git_bcommits_range = require_on_exported_call("telescope.builtin.__git").bcommits_range + --- List branches for current directory, with output from `git log --oneline` shown in the preview window --- - Default keymaps: --- - ``: checks out the currently selected branch From 068254fc7150a70d0a3365659b21340636601214 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Tue, 21 Mar 2023 22:04:44 -0400 Subject: [PATCH 03/12] Add option to run bcommits_range as operator Starts operator-pending mode and shows commits in the range of lines covered by the next text object or motion --- doc/telescope.txt | 6 ++++-- lua/telescope/builtin/__git.lua | 18 +++++++++++++++++- lua/telescope/builtin/init.lua | 1 + 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index d4f92d8c88..ccef264bac 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -1074,9 +1074,11 @@ builtin.git_bcommits_range({opts}) *telescope.builtin.git_bcommits_range()* {git_command} (table) command that will be executed. {"git","log","--pretty=oneline","--abbrev-commit","--no-patch","-L"} {start} (number) the first line in the range - (optional in visual mode) + (optional in visual or operator mode) {stop} (number) the last line in the range - (optional in visual mode) + (optional in visual or operator mode) + {operator} (boolean) select lines in operator-pending mode + (default: false) builtin.git_branches({opts}) *telescope.builtin.git_branches()* List branches for current directory, with output from `git log --oneline` diff --git a/lua/telescope/builtin/__git.lua b/lua/telescope/builtin/__git.lua index c454aecdba..f940be306a 100644 --- a/lua/telescope/builtin/__git.lua +++ b/lua/telescope/builtin/__git.lua @@ -193,6 +193,14 @@ git.bcommits = function(opts) :find() end +local last_bcommits_range_opts = {} + +local bcommits_range_callback = function() + last_bcommits_range_opts.operator = false + last_bcommits_range_opts.operator_callback = true + git.bcommits_range(last_bcommits_range_opts) +end + git.bcommits_range = function(opts) opts.current_line = (opts.current_file == nil) and get_current_buf_line(opts.winnr) or nil opts.current_file = vim.F.if_nil(opts.current_file, vim.api.nvim_buf_get_name(opts.bufnr)) @@ -206,6 +214,14 @@ git.bcommits_range = function(opts) if visual then line_number_start = vim.F.if_nil(line_number_start, vim.fn.line "v") line_number_stop = vim.F.if_nil(line_number_stop, vim.fn.line ".") + elseif opts.operator then + last_bcommits_range_opts = opts + vim.o.operatorfunc = "v:lua.require'telescope.builtin.__git'.bcommits_range_callback" + vim.api.nvim_feedkeys("g@", "n", false) + return + elseif opts.operator_callback then + line_number_start = vim.fn.line "'[" + line_number_stop = vim.fn.line "']" end local line_range = string.format("%d,%d:%s", line_number_start, line_number_stop, Path:new(opts.current_file):make_relative(opts.cwd)) @@ -545,4 +561,4 @@ local function apply_checks(mod) return mod end -return apply_checks(git) +return vim.tbl_extend("keep", apply_checks(git), { bcommits_range_callback = bcommits_range_callback }) diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index 755612985c..3b3d6646c2 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -186,6 +186,7 @@ builtin.git_bcommits = require_on_exported_call("telescope.builtin.__git").bcomm ---@field git_command table: command that will be executed. {"git","log","--pretty=oneline","--abbrev-commit","--no-patch","-L"} ---@field start number: the first line in the range (optional in visual or operator mode) ---@field stop number: the last line in the range (optional in visual or operator mode) +---@field operator boolean: select lines in operator-pending mode (default: false) builtin.git_bcommits_range = require_on_exported_call("telescope.builtin.__git").bcommits_range --- List branches for current directory, with output from `git log --oneline` shown in the preview window From 5a1503666f89162d4db6bb6e240e59c8f2e97e78 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Wed, 22 Mar 2023 10:52:17 -0400 Subject: [PATCH 04/12] Rename range arguments to "first" and "last" Can't use start/end, since end is an annoying keyword to use in lua and start/stop doesn't fit as well --- README.md | 2 +- lua/telescope/builtin/__git.lua | 14 +++++++------- lua/telescope/builtin/init.lua | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0db363e134..166af18613 100644 --- a/README.md +++ b/README.md @@ -361,7 +361,7 @@ Built-in functions. Ready to be bound to any key you like. |-------------------------------------|------------------------------------------------------------------------------------------------------------| | `builtin.git_commits` | Lists git commits with diff preview, checkout action ``, reset mixed `m`, reset soft `s` and reset hard `h` | | `builtin.git_bcommits` | Lists buffer's git commits with diff preview and checks them out on `` | -| `builtin.git_bcommits_range` | Lists buffer's git commits in a range of lines. Use options `start` and `end` to specify the range. In visual mode, lists commits for the selected lines | +| `builtin.git_bcommits_range` | Lists buffer's git commits in a range of lines. Use options `first` and `last` to specify the range. In visual mode, lists commits for the selected lines | | `builtin.git_branches` | Lists all branches with log preview, checkout action ``, track action ``, rebase action``, create action ``, switch action ``, delete action `` and merge action `` | | `builtin.git_status` | Lists current changes per file with diff preview and add action. (Multi-selection still WIP) | | `builtin.git_stash` | Lists stash items in current repository with ability to apply them on `` | diff --git a/lua/telescope/builtin/__git.lua b/lua/telescope/builtin/__git.lua index f940be306a..c219d52878 100644 --- a/lua/telescope/builtin/__git.lua +++ b/lua/telescope/builtin/__git.lua @@ -209,22 +209,22 @@ git.bcommits_range = function(opts) vim.F.if_nil(opts.git_command, { "git", "log", "--pretty=oneline", "--abbrev-commit", "--no-patch", "-L" }) local visual = string.find(vim.fn.mode(), "[vV]") ~= nil - local line_number_start = opts.start - local line_number_stop = vim.F.if_nil(opts.stop, line_number_start) + local line_number_first = opts.first + local line_number_last = vim.F.if_nil(opts.last, line_number_first) if visual then - line_number_start = vim.F.if_nil(line_number_start, vim.fn.line "v") - line_number_stop = vim.F.if_nil(line_number_stop, vim.fn.line ".") + line_number_first = vim.F.if_nil(line_number_first, vim.fn.line "v") + line_number_last = vim.F.if_nil(line_number_last, vim.fn.line ".") elseif opts.operator then last_bcommits_range_opts = opts vim.o.operatorfunc = "v:lua.require'telescope.builtin.__git'.bcommits_range_callback" vim.api.nvim_feedkeys("g@", "n", false) return elseif opts.operator_callback then - line_number_start = vim.fn.line "'[" - line_number_stop = vim.fn.line "']" + line_number_first = vim.fn.line "'[" + line_number_last = vim.fn.line "']" end local line_range = - string.format("%d,%d:%s", line_number_start, line_number_stop, Path:new(opts.current_file):make_relative(opts.cwd)) + string.format("%d,%d:%s", line_number_first, line_number_last, Path:new(opts.current_file):make_relative(opts.cwd)) pickers .new(opts, { diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index 3b3d6646c2..db89e77168 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -184,8 +184,8 @@ builtin.git_bcommits = require_on_exported_call("telescope.builtin.__git").bcomm ---@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 executed. {"git","log","--pretty=oneline","--abbrev-commit","--no-patch","-L"} ----@field start number: the first line in the range (optional in visual or operator mode) ----@field stop number: the last line in the range (optional in visual or operator mode) +---@field first number: the first line number in the range (optional in visual or operator mode) +---@field last number: the last line number in the range (default: the value of `first`) ---@field operator boolean: select lines in operator-pending mode (default: false) builtin.git_bcommits_range = require_on_exported_call("telescope.builtin.__git").bcommits_range From e5f919ea3d783fd20e2a8cd069fa20b68d6ab99f Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Wed, 22 Mar 2023 20:47:47 -0400 Subject: [PATCH 05/12] Move operators functionality to new module --- lua/telescope/builtin/__git.lua | 17 +++++------------ lua/telescope/operators.lua | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 lua/telescope/operators.lua diff --git a/lua/telescope/builtin/__git.lua b/lua/telescope/builtin/__git.lua index c219d52878..61ee427e19 100644 --- a/lua/telescope/builtin/__git.lua +++ b/lua/telescope/builtin/__git.lua @@ -2,6 +2,7 @@ local actions = require "telescope.actions" local action_state = require "telescope.actions.state" local finders = require "telescope.finders" local make_entry = require "telescope.make_entry" +local operators = require "telescope.operators" local pickers = require "telescope.pickers" local previewers = require "telescope.previewers" local utils = require "telescope.utils" @@ -193,14 +194,6 @@ git.bcommits = function(opts) :find() end -local last_bcommits_range_opts = {} - -local bcommits_range_callback = function() - last_bcommits_range_opts.operator = false - last_bcommits_range_opts.operator_callback = true - git.bcommits_range(last_bcommits_range_opts) -end - git.bcommits_range = function(opts) opts.current_line = (opts.current_file == nil) and get_current_buf_line(opts.winnr) or nil opts.current_file = vim.F.if_nil(opts.current_file, vim.api.nvim_buf_get_name(opts.bufnr)) @@ -215,9 +208,9 @@ git.bcommits_range = function(opts) line_number_first = vim.F.if_nil(line_number_first, vim.fn.line "v") line_number_last = vim.F.if_nil(line_number_last, vim.fn.line ".") elseif opts.operator then - last_bcommits_range_opts = opts - vim.o.operatorfunc = "v:lua.require'telescope.builtin.__git'.bcommits_range_callback" - vim.api.nvim_feedkeys("g@", "n", false) + opts.operator = false + opts.operator_callback = true + operators.run_operator(git.bcommits_range, opts) return elseif opts.operator_callback then line_number_first = vim.fn.line "'[" @@ -561,4 +554,4 @@ local function apply_checks(mod) return mod end -return vim.tbl_extend("keep", apply_checks(git), { bcommits_range_callback = bcommits_range_callback }) +return apply_checks(git) diff --git a/lua/telescope/operators.lua b/lua/telescope/operators.lua new file mode 100644 index 0000000000..fc07c782ec --- /dev/null +++ b/lua/telescope/operators.lua @@ -0,0 +1,19 @@ +local operators = {} + +local last_operator = {} + +operators.operator_callback = function() + last_operator.callback(last_operator.opts) +end + +-- enter operator-pending mode, see `:h map-operator` +-- params: +-- callback: the callback function to call after exiting operator-pending +-- opts: options to pass to the callback +operators.run_operator = function(callback, opts) + last_operator = { callback = callback, opts = opts } + vim.o.operatorfunc = "v:lua.require'telescope.operators'.operator_callback" + vim.api.nvim_feedkeys("g@", "mi", false) +end + +return operators From b8a62e33867417368d95d7af4ce982349ac04c38 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Wed, 22 Mar 2023 21:41:07 -0400 Subject: [PATCH 06/12] Run bcommits if no range given to bcommits_range --- doc/telescope.txt | 13 ++++++++----- lua/telescope/builtin/__git.lua | 6 ++++++ lua/telescope/builtin/init.lua | 5 +++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index ccef264bac..628df995f5 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -1055,6 +1055,7 @@ builtin.git_bcommits({opts}) *telescope.builtin.git_bcommits()* builtin.git_bcommits_range({opts}) *telescope.builtin.git_bcommits_range()* Lists commits for a range of lines in the current buffer with diff preview In visual mode, lists commits for the selected lines + With operator mode enabled, lists commits inside the text object/motion - Default keymaps or your overridden `select_` keys: - ``: checks out the currently selected commit - ``: opens a diff in a vertical split @@ -1071,12 +1072,14 @@ builtin.git_bcommits_range({opts}) *telescope.builtin.git_bcommits_range()* (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 executed. + {git_command} (table) command that will be executed. the last + element must be "-L". {"git","log","--pretty=oneline","--abbrev-commit","--no-patch","-L"} - {start} (number) the first line in the range - (optional in visual or operator mode) - {stop} (number) the last line in the range - (optional in visual or operator mode) + {first} (number) the first line number in the range + (optional in visual or operator mode; + runs git_bcommits if nil otherwise) + {last} (number) the last line number in the range + (default: the value of first) {operator} (boolean) select lines in operator-pending mode (default: false) diff --git a/lua/telescope/builtin/__git.lua b/lua/telescope/builtin/__git.lua index 61ee427e19..2a5f6f9419 100644 --- a/lua/telescope/builtin/__git.lua +++ b/lua/telescope/builtin/__git.lua @@ -215,6 +215,12 @@ git.bcommits_range = function(opts) elseif opts.operator_callback then line_number_first = vim.fn.line "'[" line_number_last = vim.fn.line "']" + elseif line_number_first == nil then + table.remove(git_command) + table.insert(git_command, "--follow") + opts.git_command = git_command + git.bcommits(opts) + return end local line_range = string.format("%d,%d:%s", line_number_first, line_number_last, Path:new(opts.current_file):make_relative(opts.cwd)) diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index db89e77168..8ae08710d3 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -174,6 +174,7 @@ builtin.git_bcommits = require_on_exported_call("telescope.builtin.__git").bcomm --- Lists commits for a range of lines in the current buffer with diff preview --- In visual mode, lists commits for the selected lines +--- With operator mode enabled, lists commits inside the text object/motion --- - Default keymaps or your overridden `select_` keys: --- - ``: checks out the currently selected commit --- - ``: opens a diff in a vertical split @@ -183,8 +184,8 @@ builtin.git_bcommits = require_on_exported_call("telescope.builtin.__git").bcomm ---@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 executed. {"git","log","--pretty=oneline","--abbrev-commit","--no-patch","-L"} ----@field first number: the first line number in the range (optional in visual or operator mode) +---@field git_command table: command that will be executed. the last element must be "-L". {"git","log","--pretty=oneline","--abbrev-commit","--no-patch","-L"} +---@field first number: the first line number in the range (optional in visual or operator mode; runs git_bcommits if nil otherwise) ---@field last number: the last line number in the range (default: the value of `first`) ---@field operator boolean: select lines in operator-pending mode (default: false) builtin.git_bcommits_range = require_on_exported_call("telescope.builtin.__git").bcommits_range From ef2e4845f5fac603abfec8101c6677dfb6f6928d Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Thu, 23 Mar 2023 06:24:17 -0400 Subject: [PATCH 07/12] Make bcommits_range default to current line Instead of calling bcommits --- doc/telescope.txt | 3 +-- lua/telescope/builtin/__git.lua | 7 ++----- lua/telescope/builtin/init.lua | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index 628df995f5..3b36ad8162 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -1076,8 +1076,7 @@ builtin.git_bcommits_range({opts}) *telescope.builtin.git_bcommits_range()* element must be "-L". {"git","log","--pretty=oneline","--abbrev-commit","--no-patch","-L"} {first} (number) the first line number in the range - (optional in visual or operator mode; - runs git_bcommits if nil otherwise) + (default: current line) {last} (number) the last line number in the range (default: the value of first) {operator} (boolean) select lines in operator-pending mode diff --git a/lua/telescope/builtin/__git.lua b/lua/telescope/builtin/__git.lua index 2a5f6f9419..d1d24ece38 100644 --- a/lua/telescope/builtin/__git.lua +++ b/lua/telescope/builtin/__git.lua @@ -216,11 +216,8 @@ git.bcommits_range = function(opts) line_number_first = vim.fn.line "'[" line_number_last = vim.fn.line "']" elseif line_number_first == nil then - table.remove(git_command) - table.insert(git_command, "--follow") - opts.git_command = git_command - git.bcommits(opts) - return + line_number_first = vim.F.if_nil(line_number_first, vim.fn.line ".") + line_number_last = vim.F.if_nil(line_number_last, vim.fn.line ".") end local line_range = string.format("%d,%d:%s", line_number_first, line_number_last, Path:new(opts.current_file):make_relative(opts.cwd)) diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index 8ae08710d3..cc0e167580 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -185,7 +185,7 @@ builtin.git_bcommits = require_on_exported_call("telescope.builtin.__git").bcomm ---@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 executed. the last element must be "-L". {"git","log","--pretty=oneline","--abbrev-commit","--no-patch","-L"} ----@field first number: the first line number in the range (optional in visual or operator mode; runs git_bcommits if nil otherwise) +---@field first number: the first line number in the range (default: current line) ---@field last number: the last line number in the range (default: the value of `first`) ---@field operator boolean: select lines in operator-pending mode (default: false) builtin.git_bcommits_range = require_on_exported_call("telescope.builtin.__git").bcommits_range From 54347c2e91aac452d8f9a413d18892250ef90f31 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Thu, 23 Mar 2023 06:42:48 -0400 Subject: [PATCH 08/12] Improve documentation of telescope.operators --- lua/telescope/operators.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lua/telescope/operators.lua b/lua/telescope/operators.lua index fc07c782ec..cd3f2511db 100644 --- a/lua/telescope/operators.lua +++ b/lua/telescope/operators.lua @@ -2,17 +2,21 @@ local operators = {} local last_operator = {} +--- Execute the last saved operator callback and options operators.operator_callback = function() last_operator.callback(last_operator.opts) end --- enter operator-pending mode, see `:h map-operator` --- params: --- callback: the callback function to call after exiting operator-pending --- opts: options to pass to the callback +--- Enters operator-pending mode, then executes callback. +--- See `:h map-operator` +--- +---@param callback function: the function to call after exiting operator-pending +---@param opts table: options to pass to the callback operators.run_operator = function(callback, opts) last_operator = { callback = callback, opts = opts } vim.o.operatorfunc = "v:lua.require'telescope.operators'.operator_callback" + -- feed g@ to enter operator-pending mode + -- 'i' required for which-key compatibility, etc. vim.api.nvim_feedkeys("g@", "mi", false) end From 9dc1af6b6f61f9498780a147d9fa94f9d18fd39d Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Thu, 23 Mar 2023 06:48:45 -0400 Subject: [PATCH 09/12] Add default value for last_operator Default to a no-op callback --- lua/telescope/operators.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/telescope/operators.lua b/lua/telescope/operators.lua index cd3f2511db..e7ee8b5f45 100644 --- a/lua/telescope/operators.lua +++ b/lua/telescope/operators.lua @@ -1,6 +1,6 @@ local operators = {} -local last_operator = {} +local last_operator = { callback = function(_) end, opts = {} } --- Execute the last saved operator callback and options operators.operator_callback = function() From 787098d149e92edf373ac88590e961ec7b2498fe Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Wed, 19 Jul 2023 00:06:00 -0400 Subject: [PATCH 10/12] Update bcommits_range for detached worktrees See #2597 --- lua/telescope/builtin/__git.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lua/telescope/builtin/__git.lua b/lua/telescope/builtin/__git.lua index d1d24ece38..0229a44638 100644 --- a/lua/telescope/builtin/__git.lua +++ b/lua/telescope/builtin/__git.lua @@ -198,8 +198,10 @@ git.bcommits_range = function(opts) opts.current_line = (opts.current_file == nil) and get_current_buf_line(opts.winnr) or nil opts.current_file = vim.F.if_nil(opts.current_file, vim.api.nvim_buf_get_name(opts.bufnr)) 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", "--no-patch", "-L" }) + opts.git_command = vim.F.if_nil( + opts.git_command, + git_command({ "log", "--pretty=oneline", "--abbrev-commit", "--no-patch", "-L" }, opts) + ) local visual = string.find(vim.fn.mode(), "[vV]") ~= nil local line_number_first = opts.first @@ -227,7 +229,7 @@ git.bcommits_range = function(opts) prompt_title = "Git BCommits in range", finder = finders.new_oneshot_job( vim.tbl_flatten { - git_command, + opts.git_command, line_range, }, opts From 459106113f79e65fd162047aa662b3d7ed9ad431 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Sat, 22 Jul 2023 11:39:48 -0400 Subject: [PATCH 11/12] Rename range arguments to "from" and "to" --- README.md | 2 +- doc/telescope.txt | 6 +++--- lua/telescope/builtin/__git.lua | 4 ++-- lua/telescope/builtin/init.lua | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 166af18613..ac883c1fcb 100644 --- a/README.md +++ b/README.md @@ -361,7 +361,7 @@ Built-in functions. Ready to be bound to any key you like. |-------------------------------------|------------------------------------------------------------------------------------------------------------| | `builtin.git_commits` | Lists git commits with diff preview, checkout action ``, reset mixed `m`, reset soft `s` and reset hard `h` | | `builtin.git_bcommits` | Lists buffer's git commits with diff preview and checks them out on `` | -| `builtin.git_bcommits_range` | Lists buffer's git commits in a range of lines. Use options `first` and `last` to specify the range. In visual mode, lists commits for the selected lines | +| `builtin.git_bcommits_range` | Lists buffer's git commits in a range of lines. Use options `from` and `to` to specify the range. In visual mode, lists commits for the selected lines | | `builtin.git_branches` | Lists all branches with log preview, checkout action ``, track action ``, rebase action``, create action ``, switch action ``, delete action `` and merge action `` | | `builtin.git_status` | Lists current changes per file with diff preview and add action. (Multi-selection still WIP) | | `builtin.git_stash` | Lists stash items in current repository with ability to apply them on `` | diff --git a/doc/telescope.txt b/doc/telescope.txt index 3b36ad8162..a571bc1a75 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -1075,10 +1075,10 @@ builtin.git_bcommits_range({opts}) *telescope.builtin.git_bcommits_range()* {git_command} (table) command that will be executed. the last element must be "-L". {"git","log","--pretty=oneline","--abbrev-commit","--no-patch","-L"} - {first} (number) the first line number in the range + {from} (number) the first line number in the range (default: current line) - {last} (number) the last line number in the range - (default: the value of first) + {to} (number) the last line number in the range + (default: the value of `from`) {operator} (boolean) select lines in operator-pending mode (default: false) diff --git a/lua/telescope/builtin/__git.lua b/lua/telescope/builtin/__git.lua index 0229a44638..1fd921f703 100644 --- a/lua/telescope/builtin/__git.lua +++ b/lua/telescope/builtin/__git.lua @@ -204,8 +204,8 @@ git.bcommits_range = function(opts) ) local visual = string.find(vim.fn.mode(), "[vV]") ~= nil - local line_number_first = opts.first - local line_number_last = vim.F.if_nil(opts.last, line_number_first) + local line_number_first = opts.from + local line_number_last = vim.F.if_nil(opts.to, line_number_first) if visual then line_number_first = vim.F.if_nil(line_number_first, vim.fn.line "v") line_number_last = vim.F.if_nil(line_number_last, vim.fn.line ".") diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index cc0e167580..c7878b7ece 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -185,8 +185,8 @@ builtin.git_bcommits = require_on_exported_call("telescope.builtin.__git").bcomm ---@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 executed. the last element must be "-L". {"git","log","--pretty=oneline","--abbrev-commit","--no-patch","-L"} ----@field first number: the first line number in the range (default: current line) ----@field last number: the last line number in the range (default: the value of `first`) +---@field from number: the first line number in the range (default: current line) +---@field to number: the last line number in the range (default: the value of `from`) ---@field operator boolean: select lines in operator-pending mode (default: false) builtin.git_bcommits_range = require_on_exported_call("telescope.builtin.__git").bcommits_range From 527caa19f1f174153fa7ef443ba15ce271b72d62 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Sat, 22 Jul 2023 16:20:25 -0400 Subject: [PATCH 12/12] Move shared bcommits picker into single function --- lua/telescope/builtin/__git.lua | 235 ++++++++++++-------------------- 1 file changed, 87 insertions(+), 148 deletions(-) diff --git a/lua/telescope/builtin/__git.lua b/lua/telescope/builtin/__git.lua index 1fd921f703..1478dc2ce6 100644 --- a/lua/telescope/builtin/__git.lua +++ b/lua/telescope/builtin/__git.lua @@ -111,6 +111,75 @@ local get_current_buf_line = function(winnr) return vim.trim(vim.api.nvim_buf_get_lines(vim.api.nvim_win_get_buf(winnr), lnum - 1, lnum, false)[1]) end +local bcommits_picker = function(opts, title, finder) + return pickers.new(opts, { + prompt_title = title, + finder = finder, + previewer = { + previewers.git_commit_diff_to_parent.new(opts), + previewers.git_commit_diff_to_head.new(opts), + previewers.git_commit_diff_as_was.new(opts), + previewers.git_commit_message.new(opts), + }, + sorter = conf.file_sorter(opts), + attach_mappings = function() + actions.select_default:replace(actions.git_checkout_current_buffer) + local transfrom_file = function() + return opts.current_file and Path:new(opts.current_file):make_relative(opts.cwd) or "" + end + + local get_buffer_of_orig = function(selection) + local value = selection.value .. ":" .. transfrom_file() + local content = utils.get_os_command_output({ "git", "--no-pager", "show", value }, opts.cwd) + + local bufnr = vim.api.nvim_create_buf(false, true) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, content) + vim.api.nvim_buf_set_name(bufnr, "Original") + return bufnr + end + + local vimdiff = function(selection, command) + local ft = vim.bo.filetype + vim.cmd "diffthis" + + local bufnr = get_buffer_of_orig(selection) + vim.cmd(string.format("%s %s", command, bufnr)) + vim.bo.filetype = ft + vim.cmd "diffthis" + + vim.api.nvim_create_autocmd("WinClosed", { + buffer = bufnr, + nested = true, + once = true, + callback = function() + vim.api.nvim_buf_delete(bufnr, { force = true }) + end, + }) + end + + actions.select_vertical:replace(function(prompt_bufnr) + actions.close(prompt_bufnr) + local selection = action_state.get_selected_entry() + vimdiff(selection, "leftabove vert sbuffer") + end) + + actions.select_horizontal:replace(function(prompt_bufnr) + actions.close(prompt_bufnr) + local selection = action_state.get_selected_entry() + vimdiff(selection, "belowright sbuffer") + end) + + actions.select_tab:replace(function(prompt_bufnr) + actions.close(prompt_bufnr) + local selection = action_state.get_selected_entry() + vim.cmd("tabedit " .. transfrom_file()) + vimdiff(selection, "leftabove vert sbuffer") + end) + return true + end, + }) +end + git.bcommits = function(opts) opts.current_line = (opts.current_file == nil) and get_current_buf_line(opts.winnr) or nil opts.current_file = vim.F.if_nil(opts.current_file, vim.api.nvim_buf_get_name(opts.bufnr)) @@ -118,80 +187,15 @@ git.bcommits = function(opts) opts.git_command = vim.F.if_nil(opts.git_command, git_command({ "log", "--pretty=oneline", "--abbrev-commit", "--follow" }, opts)) - pickers - .new(opts, { - prompt_title = "Git BCommits", - finder = finders.new_oneshot_job( - vim.tbl_flatten { - opts.git_command, - opts.current_file, - }, - opts - ), - previewer = { - previewers.git_commit_diff_to_parent.new(opts), - previewers.git_commit_diff_to_head.new(opts), - previewers.git_commit_diff_as_was.new(opts), - previewers.git_commit_message.new(opts), - }, - sorter = conf.file_sorter(opts), - attach_mappings = function() - actions.select_default:replace(actions.git_checkout_current_buffer) - local transfrom_file = function() - return opts.current_file and Path:new(opts.current_file):make_relative(opts.cwd) or "" - end - - local get_buffer_of_orig = function(selection) - local value = selection.value .. ":" .. transfrom_file() - local content = utils.get_os_command_output({ "git", "--no-pager", "show", value }, opts.cwd) - - local bufnr = vim.api.nvim_create_buf(false, true) - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, content) - vim.api.nvim_buf_set_name(bufnr, "Original") - return bufnr - end - - local vimdiff = function(selection, command) - local ft = vim.bo.filetype - vim.cmd "diffthis" - - local bufnr = get_buffer_of_orig(selection) - vim.cmd(string.format("%s %s", command, bufnr)) - vim.bo.filetype = ft - vim.cmd "diffthis" - - vim.api.nvim_create_autocmd("WinClosed", { - buffer = bufnr, - nested = true, - once = true, - callback = function() - vim.api.nvim_buf_delete(bufnr, { force = true }) - end, - }) - end - - actions.select_vertical:replace(function(prompt_bufnr) - actions.close(prompt_bufnr) - local selection = action_state.get_selected_entry() - vimdiff(selection, "leftabove vert sbuffer") - end) - - actions.select_horizontal:replace(function(prompt_bufnr) - actions.close(prompt_bufnr) - local selection = action_state.get_selected_entry() - vimdiff(selection, "belowright sbuffer") - end) - - actions.select_tab:replace(function(prompt_bufnr) - actions.close(prompt_bufnr) - local selection = action_state.get_selected_entry() - vim.cmd("tabedit " .. transfrom_file()) - vimdiff(selection, "leftabove vert sbuffer") - end) - return true - end, - }) - :find() + local title = "Git BCommits" + local finder = finders.new_oneshot_job( + vim.tbl_flatten { + opts.git_command, + opts.current_file, + }, + opts + ) + bcommits_picker(opts, title, finder):find() end git.bcommits_range = function(opts) @@ -224,80 +228,15 @@ git.bcommits_range = function(opts) local line_range = string.format("%d,%d:%s", line_number_first, line_number_last, Path:new(opts.current_file):make_relative(opts.cwd)) - pickers - .new(opts, { - prompt_title = "Git BCommits in range", - finder = finders.new_oneshot_job( - vim.tbl_flatten { - opts.git_command, - line_range, - }, - opts - ), - previewer = { - previewers.git_commit_diff_to_parent.new(opts), - previewers.git_commit_diff_to_head.new(opts), - previewers.git_commit_diff_as_was.new(opts), - previewers.git_commit_message.new(opts), - }, - sorter = conf.file_sorter(opts), - attach_mappings = function() - actions.select_default:replace(actions.git_checkout_current_buffer) - local transfrom_file = function() - return opts.current_file and Path:new(opts.current_file):make_relative(opts.cwd) or "" - end - - local get_buffer_of_orig = function(selection) - local value = selection.value .. ":" .. transfrom_file() - local content = utils.get_os_command_output({ "git", "--no-pager", "show", value }, opts.cwd) - - local bufnr = vim.api.nvim_create_buf(false, true) - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, content) - vim.api.nvim_buf_set_name(bufnr, "Original") - return bufnr - end - - local vimdiff = function(selection, command) - local ft = vim.bo.filetype - vim.cmd "diffthis" - - local bufnr = get_buffer_of_orig(selection) - vim.cmd(string.format("%s %s", command, bufnr)) - vim.bo.filetype = ft - vim.cmd "diffthis" - - vim.api.nvim_create_autocmd("WinClosed", { - buffer = bufnr, - nested = true, - once = true, - callback = function() - vim.api.nvim_buf_delete(bufnr, { force = true }) - end, - }) - end - - actions.select_vertical:replace(function(prompt_bufnr) - actions.close(prompt_bufnr) - local selection = action_state.get_selected_entry() - vimdiff(selection, "leftabove vert sbuffer") - end) - - actions.select_horizontal:replace(function(prompt_bufnr) - actions.close(prompt_bufnr) - local selection = action_state.get_selected_entry() - vimdiff(selection, "belowright sbuffer") - end) - - actions.select_tab:replace(function(prompt_bufnr) - actions.close(prompt_bufnr) - local selection = action_state.get_selected_entry() - vim.cmd("tabedit " .. transfrom_file()) - vimdiff(selection, "leftabove vert sbuffer") - end) - return true - end, - }) - :find() + local title = "Git BCommits in range" + local finder = finders.new_oneshot_job( + vim.tbl_flatten { + opts.git_command, + line_range, + }, + opts + ) + bcommits_picker(opts, title, finder):find() end git.branches = function(opts)