feat: find git root from current buffer (#2435)

This commit is contained in:
William Henrotin
2023-05-24 11:36:37 +02:00
committed by GitHub
parent 0b891ec934
commit 9f501680e5
3 changed files with 44 additions and 23 deletions

View File

@@ -967,6 +967,8 @@ builtin.git_files({opts}) *telescope.builtin.git_files()*
Options: ~ Options: ~
{cwd} (string) specify the path of the repo {cwd} (string) specify the path of the repo
{use_file_path} (boolean) if we should use the current buffer
git root (default: false)
{use_git_root} (boolean) if we should use git root as cwd or {use_git_root} (boolean) if we should use git root as cwd or
the cwd (important for submodule) the cwd (important for submodule)
(default: true) (default: true)
@@ -993,11 +995,13 @@ builtin.git_commits({opts}) *telescope.builtin.git_commits()*
{opts} (table) options to pass to the picker {opts} (table) options to pass to the picker
Options: ~ Options: ~
{cwd} (string) specify the path of the repo {cwd} (string) specify the path of the repo
{use_git_root} (boolean) if we should use git root as cwd or the cwd {use_file_path} (boolean) if we should use the current buffer git
(important for submodule) (default: true) root (default: false)
{git_command} (table) command that will be executed. {use_git_root} (boolean) if we should use git root as cwd or the cwd
{"git","log","--pretty=oneline","--abbrev-commit","--","."} (important for submodule) (default: true)
{git_command} (table) command that will be executed.
{"git","log","--pretty=oneline","--abbrev-commit","--","."}
builtin.git_bcommits({opts}) *telescope.builtin.git_bcommits()* builtin.git_bcommits({opts}) *telescope.builtin.git_bcommits()*
@@ -1013,13 +1017,15 @@ builtin.git_bcommits({opts}) *telescope.builtin.git_bcommits()*
{opts} (table) options to pass to the picker {opts} (table) options to pass to the picker
Options: ~ Options: ~
{cwd} (string) specify the path of the repo {cwd} (string) specify the path of the repo
{use_git_root} (boolean) if we should use git root as cwd or the cwd {use_file_path} (boolean) if we should use the current buffer git
(important for submodule) (default: true) root (default: false)
{current_file} (string) specify the current file that should be used {use_git_root} (boolean) if we should use git root as cwd or the cwd
for bcommits (default: current buffer) (important for submodule) (default: true)
{git_command} (table) command that will be executed. {current_file} (string) specify the current file that should be
{"git","log","--pretty=oneline","--abbrev-commit"} used for bcommits (default: current buffer)
{git_command} (table) command that will be executed.
{"git","log","--pretty=oneline","--abbrev-commit"}
builtin.git_branches({opts}) *telescope.builtin.git_branches()* builtin.git_branches({opts}) *telescope.builtin.git_branches()*
@@ -1042,6 +1048,9 @@ builtin.git_branches({opts}) *telescope.builtin.git_branches()*
Options: ~ Options: ~
{cwd} (string) specify the path of the {cwd} (string) specify the path of the
repo repo
{use_file_path} (boolean) if we should use the
current buffer git root
(default: false)
{use_git_root} (boolean) if we should use git root {use_git_root} (boolean) if we should use git root
as cwd or the cwd as cwd or the cwd
(important for submodule) (important for submodule)
@@ -1064,12 +1073,14 @@ builtin.git_status({opts}) *telescope.builtin.git_status()*
{opts} (table) options to pass to the picker {opts} (table) options to pass to the picker
Options: ~ Options: ~
{cwd} (string) specify the path of the repo {cwd} (string) specify the path of the repo
{use_git_root} (boolean) if we should use git root as cwd or the cwd {use_file_path} (boolean) if we should use the current buffer git
(important for submodule) (default: true) root (default: false)
{git_icons} (table) string -> string. Matches name with icon {use_git_root} (boolean) if we should use git root as cwd or the cwd
(see source code, make_entry.lua (important for submodule) (default: true)
git_icon_defaults) {git_icons} (table) string -> string. Matches name with icon
(see source code, make_entry.lua
git_icon_defaults)
builtin.git_stash({opts}) *telescope.builtin.git_stash()* builtin.git_stash({opts}) *telescope.builtin.git_stash()*
@@ -1082,11 +1093,13 @@ builtin.git_stash({opts}) *telescope.builtin.git_stash()*
{opts} (table) options to pass to the picker {opts} (table) options to pass to the picker
Options: ~ Options: ~
{cwd} (string) specify the path of the repo {cwd} (string) specify the path of the repo
{use_git_root} (boolean) if we should use git root as cwd or the cwd {use_file_path} (boolean) if we should use the current buffer git
(important for submodule) (default: true) root (default: false)
{show_branch} (boolean) if we should display the branch name for git {use_git_root} (boolean) if we should use git root as cwd or the cwd
stash entries (default: true) (important for submodule) (default: true)
{show_branch} (boolean) if we should display the branch name for
git stash entries (default: true)
builtin.builtin({opts}) *telescope.builtin.builtin()* builtin.builtin({opts}) *telescope.builtin.builtin()*

View File

@@ -382,6 +382,8 @@ end
local set_opts_cwd = function(opts) local set_opts_cwd = function(opts)
if opts.cwd then if opts.cwd then
opts.cwd = vim.fn.expand(opts.cwd) opts.cwd = vim.fn.expand(opts.cwd)
elseif opts.use_file_path then
opts.cwd = vim.fn.finddir(".git", vim.fn.expand "%:p" .. ";")
else else
opts.cwd = vim.loop.cwd() opts.cwd = vim.loop.cwd()
end end

View File

@@ -132,6 +132,7 @@ builtin.current_buffer_tags = require_on_exported_call("telescope.builtin.__file
--- - `<cr>`: opens the currently selected file --- - `<cr>`: opens the currently selected file
---@param opts table: options to pass to the picker ---@param opts table: options to pass to the picker
---@field cwd string: specify the path of the repo ---@field cwd string: specify the path of the repo
---@field use_file_path boolean: if we should use the current buffer git root (default: false)
---@field use_git_root boolean: if we should use git root as cwd or the cwd (important for submodule) (default: true) ---@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: false) ---@field show_untracked boolean: if true, adds `--others` flag to command and shows untracked files (default: false)
---@field recurse_submodules boolean: if true, adds the `--recurse-submodules` flag to command (default: false) ---@field recurse_submodules boolean: if true, adds the `--recurse-submodules` flag to command (default: false)
@@ -146,6 +147,7 @@ builtin.git_files = require_on_exported_call("telescope.builtin.__git").files
--- - `<C-r>h`: resets current branch to selected commit using hard mode --- - `<C-r>h`: resets current branch to selected commit using hard mode
---@param opts table: options to pass to the picker ---@param opts table: options to pass to the picker
---@field cwd string: specify the path of the repo ---@field cwd string: specify the path of the repo
---@field use_file_path boolean: if we should use the current buffer git root (default: false)
---@field use_git_root boolean: if we should use git root as cwd or the cwd (important for submodule) (default: true) ---@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 executed. {"git","log","--pretty=oneline","--abbrev-commit","--","."} ---@field git_command table: command that will be executed. {"git","log","--pretty=oneline","--abbrev-commit","--","."}
builtin.git_commits = require_on_exported_call("telescope.builtin.__git").commits builtin.git_commits = require_on_exported_call("telescope.builtin.__git").commits
@@ -158,6 +160,7 @@ builtin.git_commits = require_on_exported_call("telescope.builtin.__git").commit
--- - `<c-t>`: opens a diff in a new tab --- - `<c-t>`: opens a diff in a new tab
---@param opts table: options to pass to the picker ---@param opts table: options to pass to the picker
---@field cwd string: specify the path of the repo ---@field cwd string: specify the path of the repo
---@field use_file_path boolean: if we should use the current buffer git root (default: false)
---@field use_git_root boolean: if we should use git root as cwd or the cwd (important for submodule) (default: true) ---@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 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"} ---@field git_command table: command that will be executed. {"git","log","--pretty=oneline","--abbrev-commit"}
@@ -173,6 +176,7 @@ builtin.git_bcommits = require_on_exported_call("telescope.builtin.__git").bcomm
--- - `<C-y>`: merges the currently selected branch, with confirmation prompt before deletion --- - `<C-y>`: merges the currently selected branch, with confirmation prompt before deletion
---@param opts table: options to pass to the picker ---@param opts table: options to pass to the picker
---@field cwd string: specify the path of the repo ---@field cwd string: specify the path of the repo
---@field use_file_path boolean: if we should use the current buffer git root (default: false)
---@field use_git_root boolean: if we should use git root as cwd or the cwd (important for submodule) (default: true) ---@field use_git_root boolean: if we should use git root as cwd or the cwd (important for submodule) (default: true)
---@field show_remote_tracking_branches boolean: show remote tracking branches like origin/main (default: true) ---@field show_remote_tracking_branches boolean: show remote tracking branches like origin/main (default: true)
---@field pattern string: specify the pattern to match all refs ---@field pattern string: specify the pattern to match all refs
@@ -184,6 +188,7 @@ builtin.git_branches = require_on_exported_call("telescope.builtin.__git").branc
--- - `<cr>`: opens the currently selected file --- - `<cr>`: opens the currently selected file
---@param opts table: options to pass to the picker ---@param opts table: options to pass to the picker
---@field cwd string: specify the path of the repo ---@field cwd string: specify the path of the repo
---@field use_file_path boolean: if we should use the current buffer git root (default: false)
---@field use_git_root boolean: if we should use git root as cwd or the cwd (important for submodule) (default: true) ---@field use_git_root boolean: if we should use git root as cwd or the cwd (important for submodule) (default: true)
---@field git_icons table: string -> string. Matches name with icon (see source code, make_entry.lua git_icon_defaults) ---@field git_icons table: string -> string. Matches name with icon (see source code, make_entry.lua git_icon_defaults)
builtin.git_status = require_on_exported_call("telescope.builtin.__git").status builtin.git_status = require_on_exported_call("telescope.builtin.__git").status
@@ -193,6 +198,7 @@ builtin.git_status = require_on_exported_call("telescope.builtin.__git").status
--- - `<cr>`: runs `git apply` for currently selected stash --- - `<cr>`: runs `git apply` for currently selected stash
---@param opts table: options to pass to the picker ---@param opts table: options to pass to the picker
---@field cwd string: specify the path of the repo ---@field cwd string: specify the path of the repo
---@field use_file_path boolean: if we should use the current buffer git root (default: false)
---@field use_git_root boolean: if we should use git root as cwd or the cwd (important for submodule) (default: true) ---@field use_git_root boolean: if we should use git root as cwd or the cwd (important for submodule) (default: true)
---@field show_branch boolean: if we should display the branch name for git stash entries (default: true) ---@field show_branch boolean: if we should display the branch name for git stash entries (default: true)
builtin.git_stash = require_on_exported_call("telescope.builtin.__git").stash builtin.git_stash = require_on_exported_call("telescope.builtin.__git").stash