From 4cfab37541937cc4b5dac26277b799f7eaabdf1f Mon Sep 17 00:00:00 2001 From: Malcolm Ramsay Date: Tue, 20 Oct 2020 04:36:51 +1030 Subject: [PATCH] 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. --- lua/telescope/builtin.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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',