Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated fugitive.vim

  • Loading branch information...
commit fe97431bf233827051ab8ecdc6021c72ac856b62 1 parent 95bd700
Arthur Zapparoli authored
Showing with 103 additions and 26 deletions.
  1. +11 −9 doc/fugitive.txt
  2. +92 −17 plugin/fugitive.vim
20 doc/fugitive.txt
View
@@ -163,15 +163,17 @@ that are part of Git repositories).
scroll bound vertical split. Press enter on a line to
reblame the file as it was in that commit. You can
give any of ltwfsMC as flags and they will be passed
- along to git-blame.
-
- In a blame buffer on any line, one can press <CR> to
- reblame at that commit, ~ to reblame at that commit's
- [count]th first grandparent (like HEAD~[count]), or P
- to reblame at that commit's [count]th parent (like
- HEAD^[count]). Press o or O to open up that commit
- in a horizontal of vertical split. Pressing q will
- close the blame buffer.
+ along to git-blame. The following maps, which work on
+ the cursor line commit where sensible, are provided:
+
+ q close blame and return to blamed window
+ gq q, then |:Gedit| to return to work tree version
+ i q, then open commit
+ o open commit in horizontal split
+ O open commit in new tab
+ <CR> reblame at commit
+ ~ reblame at [count]th first grandparent
+ P reblame at [count]th parent (like HEAD^[count])
:[range]Gblame [flags] Run git-blame on the given range.
109 plugin/fugitive.vim
View
@@ -116,7 +116,7 @@ function! s:ExtractGitDir(path) abort
let ofn = ""
let nfn = fn
while fn != ofn
- if filereadable(fn . '/.git/HEAD')
+ if isdirectory(fn) && filereadable(fn . '/.git/HEAD')
return s:sub(simplify(fnamemodify(fn . '/.git',':p')),'\W$','')
elseif fn =~ '\.git$' && filereadable(fn . '/HEAD')
return s:sub(simplify(fnamemodify(fn,':p')),'\W$','')
@@ -128,7 +128,7 @@ function! s:ExtractGitDir(path) abort
endfunction
function! s:Detect(path)
- if exists('b:git_dir') && b:git_dir ==# ''
+ if exists('b:git_dir') && (b:git_dir ==# '' || b:git_dir =~# '/$')
unlet b:git_dir
endif
if !exists('b:git_dir')
@@ -158,7 +158,7 @@ augroup fugitive
autocmd BufNewFile,BufReadPost * call s:Detect(expand('<amatch>:p'))
autocmd FileType netrw call s:Detect(expand('<afile>:p'))
autocmd VimEnter * if expand('<amatch>')==''|call s:Detect(getcwd())|endif
- autocmd BufWinLeave * execute getwinvar(+winnr(), 'fugitive_leave')
+ autocmd BufWinLeave * execute getwinvar(+bufwinnr(+expand('<abuf>')), 'fugitive_leave')
augroup END
" }}}1
@@ -181,6 +181,10 @@ function! s:repo(...) abort
call s:throw('not a git repository: '.expand('%:p'))
endfunction
+function! fugitive#repo(...)
+ return call('s:repo', a:000)
+endfunction
+
function! s:repo_dir(...) dict abort
return join([self.git_dir]+a:000,'/')
endfunction
@@ -441,6 +445,8 @@ function! s:buffer_path(...) dict abort
let rev = matchstr(self.spec(),'^fugitive://.\{-\}//\zs.*')
if rev != ''
let rev = s:sub(rev,'\w*','')
+ elseif self.repo().bare()
+ let rev = '/.git'.self.spec()[strlen(self.repo().dir()) : -1]
else
let rev = self.spec()[strlen(self.repo().tree()) : -1]
endif
@@ -975,7 +981,7 @@ function! s:Edit(cmd,bang,...) abort
diffupdate
return 'redraw|echo '.string(':!'.git.' '.args)
else
- let temp = tempname()
+ let temp = resolve(tempname())
let s:temp_files[temp] = s:repo().dir()
silent execute a:cmd.' '.temp
if a:cmd =~# 'pedit'
@@ -1222,6 +1228,9 @@ function! s:diffthis()
let w:fugitive_diff_restore .= &l:wrap ? ' wrap' : ' nowrap'
let w:fugitive_diff_restore .= ' foldmethod=' . &l:foldmethod
let w:fugitive_diff_restore .= ' foldcolumn=' . &l:foldcolumn
+ if has('cursorbind')
+ let w:fugitive_diff_restore .= (&l:cursorbind ? ' ' : ' no') . 'cursorbind'
+ endif
diffthis
endif
endfunction
@@ -1442,7 +1451,7 @@ function! s:Blame(bang,line1,line2,count,args) abort
if a:count
execute 'write !'.substitute(basecmd,' blame ',' blame -L '.a:line1.','.a:line2.' ','g')
else
- let error = tempname()
+ let error = resolve(tempname())
let temp = error.'.fugitiveblame'
if &shell =~# 'csh'
silent! execute '%write !('.basecmd.' > '.temp.') >& '.error
@@ -1456,6 +1465,12 @@ function! s:Blame(bang,line1,line2,count,args) abort
if v:shell_error
call s:throw(join(readfile(error),"\n"))
endif
+ for winnr in range(winnr('$'),1,-1)
+ call setwinvar(winnr, '&scrollbind', 0)
+ if getbufvar(winbufnr(winnr), 'fugitive_blamed_bufnr')
+ execute winbufnr(winnr).'bdelete'
+ endif
+ endfor
let bufnr = bufnr('')
let restore = 'call setwinvar(bufwinnr('.bufnr.'),"&scrollbind",0)'
if &l:wrap
@@ -1464,9 +1479,6 @@ function! s:Blame(bang,line1,line2,count,args) abort
if &l:foldenable
let restore .= '|call setwinvar(bufwinnr('.bufnr.'),"&foldenable",1)'
endif
- let winnr = winnr()
- windo set noscrollbind
- exe winnr.'wincmd w'
setlocal scrollbind nowrap nofoldenable
let top = line('w0') + &scrolloff
let current = line('.')
@@ -1483,11 +1495,15 @@ function! s:Blame(bang,line1,line2,count,args) abort
if exists('+relativenumber')
setlocal norelativenumber
endif
+ nnoremap <buffer> <silent> q :exe substitute('bdelete<Bar>'.bufwinnr(b:fugitive_blamed_bufnr).' wincmd w','<Bar>-1','','')<CR>
+ nnoremap <buffer> <silent> gq :exe substitute('bdelete<Bar>'.bufwinnr(b:fugitive_blamed_bufnr).' wincmd w<Bar>if expand("%:p") =~# "^fugitive:[\\/][\\/]"<Bar>Gedit<Bar>endif','<Bar>-1','','')<CR>
nnoremap <buffer> <silent> <CR> :<C-U>exe <SID>BlameJump('')<CR>
nnoremap <buffer> <silent> P :<C-U>exe <SID>BlameJump('^'.v:count1)<CR>
nnoremap <buffer> <silent> ~ :<C-U>exe <SID>BlameJump('~'.v:count1)<CR>
- nnoremap <buffer> <silent> o :<C-U>exe <SID>Edit((&splitbelow ? "botright" : "topleft")." split", 0, matchstr(getline('.'),'\x\+'))<CR>
- nnoremap <buffer> <silent> O :<C-U>exe <SID>Edit("tabedit", 0, matchstr(getline('.'),'\x\+'))<CR>
+ nnoremap <buffer> <silent> i :<C-U>exe <SID>BlameCommit("exe 'norm q'<Bar>edit")<CR>
+ nnoremap <buffer> <silent> o :<C-U>exe <SID>BlameCommit((&splitbelow ? "botright" : "topleft")." split")<CR>
+ nnoremap <buffer> <silent> O :<C-U>exe <SID>BlameCommit("tabedit")<CR>
+ redraw
syncbind
endif
finally
@@ -1501,13 +1517,54 @@ function! s:Blame(bang,line1,line2,count,args) abort
endtry
endfunction
+function! s:BlameCommit(cmd) abort
+ let cmd = s:Edit(a:cmd, 0, matchstr(getline('.'),'\x\+'))
+ if cmd =~# '^echoerr'
+ return cmd
+ endif
+ let lnum = matchstr(getline('.'),' \zs\d\+\ze\s\+[([:digit:]]')
+ let path = matchstr(getline('.'),'^\^\=\x\+\s\+\zs.\{-\}\ze\s*\d\+ ')
+ if path ==# ''
+ let path = s:buffer(b:fugitive_blamed_bufnr).path()
+ endif
+ execute cmd
+ if search('^diff .* b/\M'.escape(path,'\').'$','W')
+ call search('^+++')
+ let head = line('.')
+ while search('^@@ \|^diff ') && getline('.') =~# '^@@ '
+ let top = +matchstr(getline('.'),' +\zs\d\+')
+ let len = +matchstr(getline('.'),' +\d\+,\zs\d\+')
+ if lnum >= top && lnum <= top + len
+ let offset = lnum - top
+ if &scrolloff
+ +
+ normal! zt
+ else
+ normal! zt
+ +
+ endif
+ while offset > 0 && line('.') < line('$')
+ +
+ if getline('.') =~# '^[ +]'
+ let offset -= 1
+ endif
+ endwhile
+ return ''
+ endif
+ endwhile
+ execute head
+ normal! zt
+ endif
+ return ''
+endfunction
+
function! s:BlameJump(suffix) abort
let commit = matchstr(getline('.'),'^\^\=\zs\x\+')
if commit =~# '^0\+$'
let commit = ':0'
endif
- let lnum = matchstr(getline('.'),'\d\+\ze\s\+[([:digit:]]')
- let path = matchstr(getline('.'),'^\^\=\zs\x\+\s\+\zs.\{-\}\ze\s*\d\+ ')
+ let lnum = matchstr(getline('.'),' \zs\d\+\ze\s\+[([:digit:]]')
+ let path = matchstr(getline('.'),'^\^\=\x\+\s\+\zs.\{-\}\ze\s*\d\+ ')
if path ==# ''
let path = s:buffer(b:fugitive_blamed_bufnr).path()
endif
@@ -1519,6 +1576,7 @@ function! s:BlameJump(suffix) abort
exe winnr.'wincmd w'
endif
execute s:Edit('edit', 0, commit.a:suffix.':'.path)
+ execute lnum
if winnr > 0
exe bufnr.'bdelete'
endif
@@ -1526,9 +1584,9 @@ function! s:BlameJump(suffix) abort
execute lnum
let delta = line('.') - line('w0') - offset
if delta > 0
- execute 'norm! 'delta."\<C-E>"
+ execute 'normal! '.delta."\<C-E>"
elseif delta < 0
- execute 'norm! '(-delta)."\<C-Y>"
+ execute 'normal! '.(-delta)."\<C-Y>"
endif
syncbind
return ''
@@ -1818,7 +1876,7 @@ function! s:BufReadIndex()
endtry
set ft=gitcommit
endif
- setlocal ro noma nomod nomodeline bufhidden=wipe
+ setlocal ro noma nomod nomodeline noswapfile bufhidden=wipe
call s:JumpInit()
nunmap <buffer> P
nunmap <buffer> ~
@@ -2000,7 +2058,9 @@ augroup END
" }}}1
" Temp files {{{1
-let s:temp_files = {}
+if !exists('s:temp_files')
+ let s:temp_files = {}
+endif
augroup fugitive_temp
autocmd!
@@ -2010,7 +2070,7 @@ augroup fugitive_temp
\ let b:git_type = 'temp' |
\ call s:Detect(expand('<amatch>:p')) |
\ setlocal bufhidden=delete |
- \ nnoremap <buffer> <silent> q :<C-U>bdelete<CR> |
+ \ nnoremap <buffer> <silent> q :<C-U>bdelete<CR>|
\ endif
augroup END
@@ -2131,6 +2191,21 @@ function! s:GF(mode) abort
elseif getline('.') =~# '^[+-]\{3\} [ab/]'
let ref = getline('.')[4:]
+ elseif getline('.') =~# '^[+-]' && search('^@@ -\d\+,\d\+ +\d\+,','bnW')
+ let type = getline('.')[0]
+ let lnum = line('.') - 1
+ let offset = -1
+ while getline(lnum) !~# '^@@ -\d\+,\d\+ +\d\+,'
+ if getline(lnum) =~# '^[ '.type.']'
+ let offset += 1
+ endif
+ let lnum -= 1
+ endwhile
+ let offset += matchstr(getline(lnum), type.'\zs\d\+')
+ let ref = getline(search('^'.type.'\{3\} [ab]/','bnW'))[4:-1]
+ let dcmd = '+'.offset.'|foldopen'
+ let dref = ''
+
elseif getline('.') =~# '^rename from '
let ref = 'a/'.getline('.')[12:]
elseif getline('.') =~# '^rename to '
Please sign in to comment.
Something went wrong with that request. Please try again.