diff options
| author | YIQUN <yiqunding@zju.edu.cn> | 2020-11-17 18:35:06 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-17 11:35:06 +0100 |
| commit | e16712f22e7702cde804f66a81437eaae5ec7d1b (patch) | |
| tree | fa0c0826d5d4d4ac888365ab69f7044d27548ecd /lua/telescope/builtin/git.lua | |
| parent | 1b12520e991e184465b5b7d5025139bfd1f1dd26 (diff) | |
Fix: set_opts_cwd function will only call git once (#256)
Diffstat (limited to 'lua/telescope/builtin/git.lua')
| -rw-r--r-- | lua/telescope/builtin/git.lua | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/lua/telescope/builtin/git.lua b/lua/telescope/builtin/git.lua index a5fdb82..4fc10f1 100644 --- a/lua/telescope/builtin/git.lua +++ b/lua/telescope/builtin/git.lua @@ -144,20 +144,19 @@ git.status = function(opts) end local set_opts_cwd = function(opts) - local is_git_dir = function(path) - vim.fn.system('cd ' .. path .. ' && git rev-parse HEAD >/dev/null 2>&1') - if vim.v.shell_error ~= 0 then - error(path .. ' is not a git directory') - end - end - if opts.cwd then opts.cwd = vim.fn.expand(opts.cwd) - is_git_dir(opts.cwd) else - is_git_dir(vim.fn.expand('%:p:h')) - --- Find root of git directory and remove trailing newline characters - opts.cwd = vim.fn.systemlist("git rev-parse --show-toplevel")[1] + opts.cwd = vim.fn.expand('%:p:h') + end + + -- Find root of git directory and remove trailing newline characters + local git_root = vim.fn.systemlist("git -C " .. opts.cwd .. " rev-parse --show-toplevel")[1] + + if vim.v.shell_error ~= 0 then + error(opts.cwd .. ' is not a git directory') + else + opts.cwd = git_root end end |
