From bdf5a221fb7b27a07f496505fb12301f7e2f9b6b Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Wed, 10 Jul 2019 09:25:34 -0400 Subject: [PATCH] Use standard argument handling for :Gfetch/:Gpush --- autoload/fugitive.vim | 45 ++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 1ed98a1..e9f5142 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -3820,41 +3820,46 @@ function! s:FetchComplete(A, L, P) abort return s:CompleteSubcommand('fetch', a:A, a:L, a:P, function('s:CompleteRemote')) endfunction -function! s:Dispatch(bang, args) +function! s:Dispatch(bang, cmd, arg) abort + let dir = s:Dir() + let [args, after] = s:SplitExpandChain(a:arg, s:Tree(dir)) let [mp, efm, cc] = [&l:mp, &l:efm, get(b:, 'current_compiler', '')] try - let cdback = s:Cd(s:Tree()) let b:current_compiler = 'git' let &l:errorformat = s:common_efm - let &l:makeprg = substitute(s:UserCommand() . ' ' . a:args, '\s\+$', '', '') + let &l:makeprg = s:shellesc(s:UserCommandList(dir) + [a:cmd] + args) if exists(':Make') == 2 Make + return after[1:-1] else - try - if !has('patch-8.1.0334') && &autowrite - let autowrite_was_set = 1 - set noautowrite - wall - endif - silent noautocmd make! - finally - if exists('autowrite_was_set') - set autowrite - endif - endtry + if !has('patch-8.1.0334') && &autowrite + let autowrite_was_set = 1 + set noautowrite + wall + endif + silent noautocmd make! redraw! - return 'call fugitive#Cwindow()|call fugitive#ReloadStatus()' + return 'call fugitive#Cwindow()|call fugitive#ReloadStatus()' . after endif - return '' finally let [&l:mp, &l:efm, b:current_compiler] = [mp, efm, cc] if empty(cc) | unlet! b:current_compiler | endif - execute cdback + if exists('autowrite_was_set') + set autowrite + endif endtry endfunction -call s:command("-nargs=? -bang -complete=customlist,s:PushComplete Gpush execute s:Dispatch('', 'push '.)") -call s:command("-nargs=? -bang -complete=customlist,s:FetchComplete Gfetch execute s:Dispatch('', 'fetch '.)") +function! s:PushCommand(line1, line2, range, count, bang, mods, reg, arg, args) abort + return s:Dispatch(a:bang ? '!' : '', 'push', a:arg) +endfunction + +function! s:FetchCommand(line1, line2, range, count, bang, mods, reg, arg, args) abort + return s:Dispatch(a:bang ? '!' : '', 'fetch', a:arg) +endfunction + +call s:command("-nargs=? -bang -complete=customlist,s:PushComplete Gpush", "Push") +call s:command("-nargs=? -bang -complete=customlist,s:FetchComplete Gfetch", "Fetch") " Section: :Gdiff