diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 46b1160..fbc337c 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -414,10 +414,6 @@ function! s:UserCommandList(...) abort return git + flags endfunction -function! s:UserCommand(...) abort - return s:shellesc(call('s:UserCommandList', a:0 ? [a:1] : []) + (a:0 ? a:2 : [])) -endfunction - let s:git_versions = {} function! fugitive#GitVersion(...) abort let git = s:GitShellCmd() @@ -3135,13 +3131,13 @@ function! s:RunWait(state, tmp, job, ...) abort try while get(a:state, 'request', '') !=# 'edit' && s:RunTick(a:job) call s:RunEcho(a:tmp) - if !get(a:state, 'closed_in') + if !get(a:tmp, 'closed_in') let peek = getchar(1) if peek != 0 && !(has('win32') && peek == 128) let c = getchar() let c = type(c) == type(0) ? nr2char(c) : c if c ==# "\" || c ==# "\" - let a:state.closed_in = 1 + let a:tmp.closed_in = 1 let can_pedit = s:RunCloseIn(a:job) && exists('*setbufline') for winnr in range(1, winnr('$')) if getwinvar(winnr, '&previewwindow') && getbufvar(winbufnr(winnr), '&modified') @@ -3181,7 +3177,7 @@ function! s:RunWait(state, tmp, job, ...) abort finally if !exists('finished') try - if a:state.pty && !get(a:state, 'closed_in') + if a:state.pty && !get(a:tmp, 'closed_in') call s:RunSend(a:job, "\") elseif type(a:job) == type(0) call jobstop(a:job) @@ -3293,7 +3289,7 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg) abort if args[0] ==# '-c' && len(args) > 1 call extend(flags, remove(args, 0, 1)) elseif args[0] =~# '^-p$\|^--paginate$' - let pager = 1 + let pager = 2 call remove(args, 0) elseif args[0] =~# '^-P$\|^--no-pager$' let pager = 0 @@ -3359,22 +3355,15 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg) abort let i += 1 endwhile call s:PrepareEnv(env, dir) - let editcmd = a:line2 ? 'split' : 'edit' - if pager is# 1 - if a:bang && a:line2 >= 0 - let editcmd = 'read' - elseif a:bang - let editcmd = 'pedit' - endif - elseif pager is# -1 + if pager is# -1 let pager = fugitive#PagerFor(args, config) if a:bang && pager isnot# 1 return 'echoerr ' . string('fugitive: :Git! for temp buffer output has been replaced by :Git --paginate') endif endif - if (s:HasOpt(args, ['add', 'checkout', 'commit', 'stage', 'stash', 'reset'], '-p', '--patch') || - \ s:HasOpt(args, ['add', 'clean', 'stage'], '-i', '--interactive') || - \ type(pager) == type('')) && pager isnot# 1 + if type(pager) ==# type('') || + \ (s:HasOpt(args, ['add', 'checkout', 'commit', 'stage', 'stash', 'reset'], '-p', '--patch') || + \ s:HasOpt(args, ['add', 'clean', 'stage'], '-i', '--interactive')) && pager is# 0 let mods = substitute(s:Mods(a:mods), '\', '-tab', 'g') let assign = len(dir) ? '|let b:git_dir = ' . string(dir) : '' let argv = s:UserCommandList(options) + args @@ -3390,9 +3379,6 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg) abort return mods . 'call term_start(' . string(argv) . ', ' . string(term_opts) . ')' . assign . after endif endif - if pager is# 1 && editcmd ==# 'read' - return s:ReadExec(a:line1, a:line2, a:range, a:mods, env, args, options) . after - endif let state = { \ 'git': git, \ 'flags': flags, @@ -3403,13 +3389,24 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg) abort \ 'filetype': 'git', \ 'mods': s:Mods(a:mods), \ 'file': s:Resolve(tempname())} - if pager is# 1 + if pager + let after_edit = '' + if pager is# 2 && a:bang && a:line2 >= 0 + let [do_edit, after_edit] = s:ReadPrepare(a:line1, a:line2, a:range, a:mods) + elseif pager is# 2 && a:bang + let do_edit = s:Mods(a:mods) . 'pedit' + elseif a:line2 + let do_edit = s:Mods(a:mods) . 'split' + else + let do_edit = s:Mods(a:mods) . 'edit' + call s:BlurStatus() + endif call extend(env, {'COLUMNS': '' . get(g:, 'fugitive_columns', 80)}, 'keep') else call extend(env, {'COLUMNS': '' . &columns - 1}, 'keep') endif - if s:RunJobs() && pager isnot# 1 - let state.pty = get(g:, 'fugitive_pty', has('unix') && !has('win32unix') && (has('patch-8.0.0744') || has('nvim')) && fugitive#GitVersion() !~# '\.windows\>') + if s:RunJobs() + let state.pty = !pager && get(g:, 'fugitive_pty', has('unix') && !has('win32unix') && (has('patch-8.0.0744') || has('nvim')) && fugitive#GitVersion() !~# '\.windows\>') if !state.pty let args = s:AskPassArgs(dir) + args endif @@ -3417,7 +3414,6 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg) abort \ 'line_count': 0, \ 'err': '', \ 'out': '', - \ 'echo': '', \ 'escape': ''} let env.FUGITIVE = state.file let editor = 'sh ' . s:TempScript( @@ -3430,16 +3426,24 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg) abort \ 'NO_COLOR': '1', \ 'GIT_EDITOR': editor, \ 'GIT_SEQUENCE_EDITOR': editor, - \ 'GIT_MERGE_AUTOEDIT': '1', \ 'GIT_PAGER': 'cat', \ 'PAGER': 'cat'}, 'keep') + if pager + call writefile(['fugitive: aborting edit due to use of pager.'], state.file . '.exit') + let after = '|' . do_edit . ' ' . s:fnameescape(state.file) . after_edit . after + else + let env.GIT_MERGE_AUTOEDIT = '1' + let tmp.echo = '' + endif let args = s:disable_colors + flags + ['-c', 'advice.waitingForEditor=false'] + args let argv = s:UserCommandList({'git': git, 'git_dir': dir}) + args let [argv, jobopts] = s:JobOpts(argv, env) call fugitive#Autowrite() call writefile([], state.file, 'b') call s:RunSave(state) - echo "" + if has_key(tmp, 'echo') + echo "" + endif if exists('*job_start') call extend(jobopts, { \ 'mode': 'raw', @@ -3462,9 +3466,13 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg) abort \ })) endif let state.job = job + if pager + let tmp.closed_in = 1 + call s:RunCloseIn(job) + endif call add(s:resume_queue, [state, tmp, job]) return 'call fugitive#Resume()|silent checktime' . after - elseif pager is# 1 + elseif pager let pre = s:BuildEnvPrefix(env) try if exists('+guioptions') && &guioptions =~# '!' @@ -3482,10 +3490,7 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg) abort redraw! call s:RunSave(state) call s:RunFinished(state) - if editcmd ==# 'edit' - call s:BlurStatus() - endif - return state.mods . editcmd . ' ' . s:fnameescape(state.file) . + return do_edit . ' ' . s:fnameescape(state.file) . after_edit . \ '|call fugitive#ReloadStatus(fugitive#Result(' . string(state.file) . '), 1)' . after elseif has('win32') return 'echoerr ' . string('fugitive: Vim 8 with job support required to use :Git on Windows') @@ -5602,26 +5607,7 @@ function! s:ReadPrepare(line1, count, range, mods) abort else let pre = '' endif - return [pre . 'keepalt ' . mods . after . 'read', delete . 'diffupdate' . (a:count < 0 ? '|' . line('.') : '')] -endfunction - -function! s:ReadExec(line1, count, range, mods, env, args, options) abort - let [read, post] = s:ReadPrepare(a:line1, a:count, a:range, a:mods) - let env = s:BuildEnvPrefix(extend({'COLUMNS': &tw ? &tw : 80}, a:env)) - try - if exists('+guioptions') && &guioptions =~# '!' - let guioptions = &guioptions - set guioptions-=! - endif - silent execute read . '!' escape(env . s:UserCommand(a:options, ['--no-pager'] + a:args), '!#%') - finally - if exists('guioptions') - let &guioptions = guioptions - endif - endtry - execute post - call fugitive#ReloadStatus(a:options.dir, 1) - return 'redraw|echo '.string(':!'.s:UserCommand(a:options, a:args)) + return [pre . 'keepalt ' . mods . after . 'read', '|' . delete . 'diffupdate' . (a:count < 0 ? '|' . line('.') : '')] endfunction function! fugitive#ReadCommand(line1, count, range, bang, mods, arg, args) abort @@ -5638,7 +5624,7 @@ function! fugitive#ReadCommand(line1, count, range, bang, mods, arg, args) abort if file =~# '^fugitive:' && a:count is# 0 return 'exe ' .string('keepalt ' . s:Mods(a:mods) . fugitive#FileReadCmd(file, 0, pre)) . '|diffupdate' endif - return read . ' ' . pre . ' ' . s:fnameescape(file) . '|' . post + return read . ' ' . pre . ' ' . s:fnameescape(file) . post endfunction function! fugitive#EditComplete(A, L, P) abort