Fix: set_opts_cwd function will only call git once (#256)
This commit is contained in:
@@ -144,20 +144,19 @@ git.status = function(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local set_opts_cwd = function(opts)
|
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
|
if opts.cwd then
|
||||||
opts.cwd = vim.fn.expand(opts.cwd)
|
opts.cwd = vim.fn.expand(opts.cwd)
|
||||||
is_git_dir(opts.cwd)
|
|
||||||
else
|
else
|
||||||
is_git_dir(vim.fn.expand('%:p:h'))
|
opts.cwd = vim.fn.expand('%:p:h')
|
||||||
--- Find root of git directory and remove trailing newline characters
|
end
|
||||||
opts.cwd = vim.fn.systemlist("git rev-parse --show-toplevel")[1]
|
|
||||||
|
-- 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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user