mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-08 05:24:47 +08:00
[GFiles] fzf#vim#gitfiles should respect 'dir'
https://github.com/junegunn/fzf.vim/pull/1290#issuecomment-1207832597
This commit is contained in:
@@ -603,14 +603,15 @@ endfunction
|
|||||||
" GFiles[?]
|
" GFiles[?]
|
||||||
" ------------------------------------------------------------------
|
" ------------------------------------------------------------------
|
||||||
|
|
||||||
function! s:get_git_root()
|
function! s:get_git_root(dir)
|
||||||
let bufdir = substitute(split(expand('%:p:h'), '[/\\]\.git\([/\\]\|$\)')[0], '^fugitive://', '', '')
|
let dir = len(a:dir) ? a:dir : substitute(split(expand('%:p:h'), '[/\\]\.git\([/\\]\|$\)')[0], '^fugitive://', '', '')
|
||||||
let root = systemlist('git -C ' . fzf#shellescape(bufdir) . ' rev-parse --show-toplevel')[0]
|
let root = systemlist('git -C ' . fzf#shellescape(dir) . ' rev-parse --show-toplevel')[0]
|
||||||
return v:shell_error ? '' : root
|
return v:shell_error ? '' : (len(a:dir) ? fnamemodify(a:dir, ':p') : root)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fzf#vim#gitfiles(args, ...)
|
function! fzf#vim#gitfiles(args, ...)
|
||||||
let root = s:get_git_root()
|
let dir = get(get(a:, 1, {}), 'dir', '')
|
||||||
|
let root = s:get_git_root(dir)
|
||||||
if empty(root)
|
if empty(root)
|
||||||
return s:warn('Not in git repo')
|
return s:warn('Not in git repo')
|
||||||
endif
|
endif
|
||||||
@@ -618,7 +619,6 @@ function! fzf#vim#gitfiles(args, ...)
|
|||||||
if a:args != '?'
|
if a:args != '?'
|
||||||
return s:fzf('gfiles', {
|
return s:fzf('gfiles', {
|
||||||
\ 'source': prefix . 'ls-files '.a:args.(s:is_win ? '' : ' | uniq'),
|
\ 'source': prefix . 'ls-files '.a:args.(s:is_win ? '' : ' | uniq'),
|
||||||
\ 'dir': root,
|
|
||||||
\ 'options': '-m --prompt "GitFiles> "'
|
\ 'options': '-m --prompt "GitFiles> "'
|
||||||
\}, a:000)
|
\}, a:000)
|
||||||
endif
|
endif
|
||||||
@@ -635,7 +635,6 @@ function! fzf#vim#gitfiles(args, ...)
|
|||||||
\ s:bin.preview)
|
\ s:bin.preview)
|
||||||
let wrapped = fzf#wrap({
|
let wrapped = fzf#wrap({
|
||||||
\ 'source': prefix . '-c color.status=always status --short --untracked-files=all',
|
\ 'source': prefix . '-c color.status=always status --short --untracked-files=all',
|
||||||
\ 'dir': root,
|
|
||||||
\ 'options': ['--ansi', '--multi', '--nth', '2..,..', '--tiebreak=index', '--prompt', 'GitFiles?> ', '--preview', preview]
|
\ 'options': ['--ansi', '--multi', '--nth', '2..,..', '--tiebreak=index', '--prompt', 'GitFiles?> ', '--preview', preview]
|
||||||
\})
|
\})
|
||||||
call s:remove_layout(wrapped)
|
call s:remove_layout(wrapped)
|
||||||
@@ -1189,7 +1188,7 @@ function! s:commits_sink(lines)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:commits(range, buffer_local, args)
|
function! s:commits(range, buffer_local, args)
|
||||||
let s:git_root = s:get_git_root()
|
let s:git_root = s:get_git_root('')
|
||||||
if empty(s:git_root)
|
if empty(s:git_root)
|
||||||
return s:warn('Not in git repository')
|
return s:warn('Not in git repository')
|
||||||
endif
|
endif
|
||||||
|
|||||||
Reference in New Issue
Block a user