diff options
| author | Malcolm Ramsay <malramsay64@gmail.com> | 2020-10-20 04:36:51 +1030 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-19 14:06:51 -0400 |
| commit | 4cfab37541937cc4b5dac26277b799f7eaabdf1f (patch) | |
| tree | df6ba217e196ddc9a2b11a000f442190bef316a0 /lua/telescope/builtin.lua | |
| parent | 3cd163c9d05b65d917ebb9326d060d5fcc1ab83d (diff) | |
Ensure git_files uses the git root directory as cwd (#180)
* fix: Ensure git_files uses the git root directory as cwd
This sets the cwd option of the git_files builtin to use the root of the
git directory when the cwd option doesn't already exist. When git lists
files, it is relative to the root of the git directory, rather than the
current working directory. This caused problems when using git_files in
a subdirectory of the git root (see #174).
This commit fixes the issue by always setting the cwd as the root of the
git directory.
* ref: Use neovim's system caller for command
This removes the need for an additional lua function to extract the shell
response, making use of inbuilt vim functionality.
Diffstat (limited to 'lua/telescope/builtin.lua')
| -rw-r--r-- | lua/telescope/builtin.lua | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lua/telescope/builtin.lua b/lua/telescope/builtin.lua index 74b277c..5261243 100644 --- a/lua/telescope/builtin.lua +++ b/lua/telescope/builtin.lua @@ -46,10 +46,15 @@ local builtin = {} builtin.git_files = function(opts) opts = opts or {} - opts.entry_maker = opts.entry_maker or make_entry.gen_from_file(opts) if opts.cwd then opts.cwd = vim.fn.expand(opts.cwd) + else + --- Find root of git directory and remove trailing newline characters + opts.cwd = string.gsub(vim.fn.system("git rev-parse --show-toplevel"), '[\n\r]+', '') end + -- 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) pickers.new(opts, { prompt_title = 'Git File', |
