Support Git flags inside of aliases

Resolves: https://github.com/tpope/vim-fugitive/issues/2298
This commit is contained in:
Tim Pope
2024-05-01 18:16:45 -04:00
parent dac8e5c2d8
commit ce882460cf

View File

@@ -3768,6 +3768,7 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg, ...) abort
let flags = [] let flags = []
let pager = -1 let pager = -1
let explicit_pathspec_option = 0 let explicit_pathspec_option = 0
let did_expand_alias = 0
while len(args) while len(args)
if args[0] ==# '-c' && len(args) > 1 if args[0] ==# '-c' && len(args) > 1
call extend(flags, remove(args, 0, 1)) call extend(flags, remove(args, 0, 1))
@@ -3784,8 +3785,18 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg, ...) abort
call add(flags, remove(args, 0)) call add(flags, remove(args, 0))
elseif args[0] =~# '^-C$\|^--\%(exec-path=\|git-dir=\|work-tree=\|bare$\)' elseif args[0] =~# '^-C$\|^--\%(exec-path=\|git-dir=\|work-tree=\|bare$\)'
return 'echoerr ' . string('fugitive: ' . args[0] . ' is not supported') return 'echoerr ' . string('fugitive: ' . args[0] . ' is not supported')
else elseif did_expand_alias
break break
else
let alias = FugitiveConfigGet('alias.' . get(args, 0, ''), config)
if get(args, 1, '') !=# '--help' && alias !~# '^$\|^!\|[\"'']' && !filereadable(s:VimExecPath() . '/git-' . args[0])
\ && !(has('win32') && filereadable(s:VimExecPath() . '/git-' . args[0] . '.exe'))
call remove(args, 0)
call extend(args, split(alias, '\s\+'), 'keep')
let did_expand_alias = 1
else
break
endif
endif endif
endwhile endwhile
if !explicit_pathspec_option if !explicit_pathspec_option
@@ -3817,12 +3828,6 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg, ...) abort
let cmd = s:StatusCommand(a:line1, a:line2, a:range, curwin ? 0 : a:line2, a:bang, a:mods, '', '', [], options) let cmd = s:StatusCommand(a:line1, a:line2, a:range, curwin ? 0 : a:line2, a:bang, a:mods, '', '', [], options)
return (empty(cmd) ? 'exe' : cmd) . after return (empty(cmd) ? 'exe' : cmd) . after
endif endif
let alias = FugitiveConfigGet('alias.' . get(args, 0, ''), config)
if get(args, 1, '') !=# '--help' && alias !~# '^$\|^!\|[\"'']' && !filereadable(s:VimExecPath() . '/git-' . args[0])
\ && !(has('win32') && filereadable(s:VimExecPath() . '/git-' . args[0] . '.exe'))
call remove(args, 0)
call extend(args, split(alias, '\s\+'), 'keep')
endif
let name = substitute(get(args, 0, ''), '\%(^\|-\)\(\l\)', '\u\1', 'g') let name = substitute(get(args, 0, ''), '\%(^\|-\)\(\l\)', '\u\1', 'g')
if pager is# -1 && name =~# '^\a\+$' && exists('*s:' . name . 'Subcommand') && get(args, 1, '') !=# '--help' if pager is# -1 && name =~# '^\a\+$' && exists('*s:' . name . 'Subcommand') && get(args, 1, '') !=# '--help'
try try