From ce882460cf3db12e99f8bf579cbf99e331f6dd4f Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Wed, 1 May 2024 18:16:45 -0400 Subject: [PATCH] Support Git flags inside of aliases Resolves: https://github.com/tpope/vim-fugitive/issues/2298 --- autoload/fugitive.vim | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 69f6346..c333060 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -3768,6 +3768,7 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg, ...) abort let flags = [] let pager = -1 let explicit_pathspec_option = 0 + let did_expand_alias = 0 while len(args) if args[0] ==# '-c' && len(args) > 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)) elseif args[0] =~# '^-C$\|^--\%(exec-path=\|git-dir=\|work-tree=\|bare$\)' return 'echoerr ' . string('fugitive: ' . args[0] . ' is not supported') - else + elseif did_expand_alias 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 endwhile 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) return (empty(cmd) ? 'exe' : cmd) . after 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') if pager is# -1 && name =~# '^\a\+$' && exists('*s:' . name . 'Subcommand') && get(args, 1, '') !=# '--help' try