diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index 826a9a5..b7e2702 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -956,6 +956,74 @@ function! s:StagePatch(lnum1,lnum2) abort return 'checktime' endfunction +" Section: Gpush, Gfetch + +let s:errorformat = '' + \ . 'CONFLICT (%m): Merge %.%# %f,' + \ . 'CONFLICT (%m): %f %.%#,' + \ . 'U%\t%f,' + \ . '%tRROR: %m,' + \ . '%trror: %m,' + \ . '%tarning: %m,' + \ . '%Ausage: %m,' + \ . '%Efatal: %m,' + \ . '%+ECannot %.%#: %.%#,' + \ . '%C%m,' + \ . '%+ITo %.%#,' + \ . '%+IFrom %.%#,' + \ . '%+I %.%# -> %.%#,' + \ . '%-G%.%#' + +let s:errorformat = '' + \ . 'CONFLICT (%m): Merge %.%# %f,' + \ . 'CONFLICT (%m): %f %.%#,' + \ . '%+A%\w%\t%f,' + \ . '%+EERROR: %.%#,' + \ . '%+Eerror: %.%#,' + \ . '%+Wwarning: %.%#,' + \ . '%+Iusage: %.%#,' + \ . '%+Efatal: %.%#,' + \ . '%+ECannot %.%#: %.%#,' + \ . '%-G%.%#%\rhihihi%.%\+' + +call s:command("-nargs=? -bang Gpush execute s:Dispatch('', 'push --progress '.)") +call s:command("-nargs=? -bang Gfetch execute s:Dispatch('', 'fetch --progress '.)") + +function! fugitive#cwindow() abort + if empty(filter(getqflist(), 'v:val.valid')) + cclose + else + copen + wincmd p + endif +endfunction + +function! s:Dispatch(bang, args) + let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd' + let cwd = getcwd() + let [mp, efm, cc] = [&l:mp, &l:efm, get(b:, 'current_compiler', '')] + try + let b:current_compiler = 'git' + let &l:errorformat = s:errorformat + let &l:makeprg = g:fugitive_git_executable . ' ' . a:args + cclose + execute cd fnameescape(s:repo().tree()) + if exists(':Make') == 2 + execute 'Make'.a:bang + elseif !empty(a:bang) + call feedkeys(":redraw!|call fugitive#cwindow()\r", 'n') + silent make! + else + call feedkeys(":redraw!\r", 'n') + silent make! + endif + finally + let [&l:mp, &l:efm, b:current_compiler] = [mp, efm, cc] + if empty(cc) | unlet! b:current_compiler | endif + execute cd fnameescape(cwd) + endtry +endfunction + " Section: Gcommit call s:command("-nargs=? -complete=customlist,s:CommitComplete Gcommit :execute s:Commit()") @@ -1057,6 +1125,88 @@ function! s:FinishCommit() abort return '' endfunction +" Section: Gpull, Gmerge + +call s:command("-nargs=? -bang Gpull :execute s:Merge('pull --progress', 0, )") +call s:command("-nargs=? -bang -complete=customlist,s:EditComplete Gmerge " . + \ "execute s:Merge('merge', 0, )") + +function! s:Merge(cmd, bang, args) abort + let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd' + let cwd = getcwd() + let [mp, efm] = [&l:mp, &l:efm] + try + " Automatic merge went well; stopped before committing as requested + let ourefm = '' + \ . '%-G%.%#%\e%.%#,' + \ . '%-Gerror:%.%#false''.,' + \ . '%-G%.%# ''git commit'' %.%#,' + \ . '%+Eerror:%.%#,' + \ . '%+Efatal:%.%#,' + \ . '%+ECannot %.%#: %.%#,' + \ . '%+EThere is no tracking information for the current branch.,' + \ . '%+EYou are not currently on a branch. Please specify which,' + \ . 'CONFLICT (%m): %f deleted in %.%#,' + \ . 'CONFLICT (%m): Merge conflict in %f,' + \ . 'CONFLICT (%m): Rename \"%f\"->%.%#,' + \ . 'CONFLICT (%m): Rename %.%#->%f %.%#,' + \ . 'CONFLICT (%m): There is a directory with name %f in %.%#,' + \ . '%+ECONFLICT %.%#,' + \ . '%+EKONFLIKT %.%#,' + \ . '%+ECONFLIT %.%#,' + \ . "%+EXUNG \u0110\u1ed8T %.%#," + \ . "%+E\u51b2\u7a81 %.%#," + \ . '%m%\t%f,' + \ . '%\t%f' + let &l:errorformat = ourefm + let &l:makeprg = s:sub(g:fugitive_git_executable.' -c core.editor=false '. + \ a:cmd . (a:args =~# ' \%(--no-edit\|--abort\|-m\)\>' ? '' : ' --edit') . ' ' . a:args, + \ ' *$', '') + if !empty($GIT_EDITOR) + let old_editor = $GIT_EDITOR + let $GIT_EDITOR = 'false' + endif + execute cd fnameescape(s:repo().tree()) + let err = '' + cclose + try + silent make! + redraw! + if &efm != ourefm + verbose set efm? + endif + catch /^Vim\%((\a\+)\)\=:E211/ + let err = v:exception + endtry + call fugitive#reload_status() + if empty(filter(getqflist(),'v:val.valid')) + for file in ['MERGE_MSG', 'SQUASH_MSG'] + if filereadable(s:repo().dir(file)) + return 'Gcommit --no-status -t '.s:shellesc(s:repo().dir(file)) + endif + endfor + endif + let qflist = getqflist() + let found = 0 + for e in qflist + if !empty(e.bufnr) && e.text =~# '..\|U' + let found = 1 + let e.pattern = '^<<<<<<<' + endif + endfor + if found + call setqflist(qflist, 'r') + endif + return 'botr cwindow|wincmd p' . (empty(err) ? '' : '|echoerr '.string(err)) + finally + let [&l:mp, &l:efm] = [mp, efm] + if exists('old_editor') + let $GIT_EDITOR = old_editor + endif + execute cd fnameescape(cwd) + endtry +endfunction + augroup fugitive_commit autocmd! autocmd VimLeavePre,BufDelete COMMIT_EDITMSG execute s:sub(s:FinishCommit(), '^echoerr (.*)', 'echohl ErrorMsg|echo \1|echohl NONE') @@ -1159,7 +1309,9 @@ function! s:Edit(cmd,bang,...) abort if winnr != mywinnr && getwinvar(winnr,'&diff') execute winnr.'wincmd w' close - wincmd p + if winnr('$') > 1 + wincmd p + endif endif endfor endif