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:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user