feat: allow git_* to use vim pwd over git root (#563)

with opt use_git_root = false
Examples:
- Telescope git_files use_git_root=false
- Telescope git_commits use_git_root=false
- Telescope git_status use_git_root=false
This commit is contained in:
Tom
2021-02-27 11:04:30 +00:00
committed by GitHub
parent d37dc88eab
commit 49650f5d74

View File

@@ -37,7 +37,9 @@ git.files = function(opts)
end end
git.commits = function(opts) git.commits = function(opts)
local results = utils.get_os_command_output({ 'git', 'log', '--pretty=oneline', '--abbrev-commit' }, opts.cwd) local results = utils.get_os_command_output({
'git', 'log', '--pretty=oneline', '--abbrev-commit', '--', '.'
}, opts.cwd)
pickers.new(opts, { pickers.new(opts, {
prompt_title = 'Git Commits', prompt_title = 'Git Commits',
@@ -110,7 +112,7 @@ end
git.status = function(opts) git.status = function(opts)
local gen_new_finder = function() local gen_new_finder = function()
local output = utils.get_os_command_output({ 'git', 'status', '-s' }, opts.cwd) local output = utils.get_os_command_output({ 'git', 'status', '-s', '--', '.' }, opts.cwd)
if table.getn(output) == 0 then if table.getn(output) == 0 then
print('No changes found') print('No changes found')
@@ -154,11 +156,14 @@ local set_opts_cwd = function(opts)
-- Find root of git directory and remove trailing newline characters -- 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] local git_root = vim.fn.systemlist("git -C " .. opts.cwd .. " rev-parse --show-toplevel")[1]
local use_git_root = utils.get_default(opts.use_git_root, true)
if vim.v.shell_error ~= 0 then if vim.v.shell_error ~= 0 then
error(opts.cwd .. ' is not a git directory') error(opts.cwd .. ' is not a git directory')
else else
opts.cwd = git_root if use_git_root then
opts.cwd = git_root
end
end end
end end