feat(git): Add bcommits_range picker (#2398)

* Filter bcommits by selection in visual mode

* Split bcommits_range into new picker

* 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

* 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

* Move operators functionality to new module

* Run bcommits if no range given to bcommits_range

* Make bcommits_range default to current line

Instead of calling bcommits

* Improve documentation of telescope.operators

* Add default value for last_operator

Default to a no-op callback

* Update bcommits_range for detached worktrees

See #2597

* Rename range arguments to "from" and "to"

* Move shared bcommits picker into single function
This commit is contained in:
Aaron Kollasch
2023-07-22 17:35:52 -04:00
committed by GitHub
parent f78d956901
commit e7e6492a2d
5 changed files with 189 additions and 71 deletions

View File

@@ -172,6 +172,24 @@ 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
--- With operator mode enabled, lists commits inside the text object/motion
--- - Default keymaps or your overridden `select_` keys:
--- - `<cr>`: checks out the currently selected commit
--- - `<c-v>`: opens a diff in a vertical split
--- - `<c-x>`: opens a diff in a horizontal split
--- - `<c-t>`: 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. the last element must be "-L". {"git","log","--pretty=oneline","--abbrev-commit","--no-patch","-L"}
---@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
--- List branches for current directory, with output from `git log --oneline` shown in the preview window
--- - Default keymaps:
--- - `<cr>`: checks out the currently selected branch