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.
This commit is contained in:
Malcolm Ramsay
2020-10-20 04:36:51 +10:30
committed by GitHub
parent 3cd163c9d0
commit 4cfab37541

View File

@@ -46,10 +46,15 @@ local builtin = {}
builtin.git_files = function(opts) builtin.git_files = function(opts)
opts = opts or {} opts = opts or {}
opts.entry_maker = opts.entry_maker or make_entry.gen_from_file(opts)
if opts.cwd then if opts.cwd then
opts.cwd = vim.fn.expand(opts.cwd) 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 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, { pickers.new(opts, {
prompt_title = 'Git File', prompt_title = 'Git File',