Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
doc/tags
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Usage
### Commands

- `:GV` to open commit browser
- You can pass `git log` options to the command, e.g. `:GV -S foobar`.
- You can pass `git log` options to the command, e.g. `:GV -S foobar -- plugins`.
- `:GV!` will only list commits that affected the current file
- `:GV?` fills the location list with the revisions of the current file

Expand All @@ -39,7 +39,7 @@ selected lines.
- `o` or `<cr>` on a commit to display the content of it
- `o` or `<cr>` on commits to display the diff in the range
- `O` opens a new tab instead
- `gb` for `:Gbrowse`
- `gb` for `:GBrowse`
- `]]` and `[[` to move between commits
- `.` to start command-line with `:Git [CURSOR] SHA` à la fugitive
- `q` or `gq` to close
Expand Down
30 changes: 30 additions & 0 deletions doc/gv-vim.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
gv-vim.txt gv-vim

COMMANDS *gv-vim-commands*
==============================================================================

-----------------+-------------------------------------------------------------------
Command | List ~
-----------------+-------------------------------------------------------------------
`GV` | open commit browser -- You can pass git log options to the command, e.g. :GV -S foobar
`GV!` | will only list commits that affected the current file
`GV?` | fills the location list with the revisions of the current file
---------------+-------------------------------------------------------------------

MAPPINGS *gv-vim-mappings*
==============================================================================

The following maps, work inside the "gv-buffer"

---------------------------------+------------------------------------------
Mapping | Description ~
---------------------------------+------------------------------------------
<C-n> | Same as jo
<C-p> | Same as ko
gb | open github on this commit
<cr> | display the diff in the range - display diff on commit if range omited
o | same as cr
O | similar to <cr> but opens a new tab instead
. | start command-line with :Git [CURSOR] SHA à la fugitive
q | close
---------------------------------+------------------------------------------
99 changes: 50 additions & 49 deletions plugin/gv.vim
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function! s:gbrowse()
if empty(sha)
return s:shrug()
endif
execute 'Gbrowse' sha
execute 'GBrowse' sha
endfunction

function! s:type(visual)
Expand All @@ -61,7 +61,7 @@ function! s:type(visual)
if len(shas) < 2
return [0, 0]
endif
return ['diff', fugitive#repo().git_command('diff', shas[-1], shas[0])]
return ['diff', FugitiveShellCommand(['diff', shas[-1], shas[0]])]
endif

if exists('b:git_origin')
Expand Down Expand Up @@ -106,6 +106,7 @@ function! s:open(visual, ...)
call s:scratch()
if type == 'commit'
execute 'e' escape(target, ' ')
call s:disableDimInactive()
nnoremap <silent> <buffer> gb :Gbrowse<cr>
elseif type == 'diff'
call s:fill(target)
Expand All @@ -125,50 +126,30 @@ function! s:dot()
return empty(sha) ? '' : ':Git '.sha."\<s-left>\<left>"
endfunction

function! s:syntax()
setf GV
syn clear
syn match gvInfo /^[^0-9]*\zs[0-9-]\+\s\+[a-f0-9]\+ / contains=gvDate,gvSha nextgroup=gvMessage,gvMeta
syn match gvDate /\S\+ / contained
syn match gvSha /[a-f0-9]\{6,}/ contained
syn match gvMessage /.* \ze(.\{-})$/ contained contains=gvTag,gvGitHub,gvJira nextgroup=gvAuthor
syn match gvAuthor /.*$/ contained
syn match gvMeta /([^)]\+) / contained contains=gvTag nextgroup=gvMessage
syn match gvTag /(tag:[^)]\+)/ contained
syn match gvGitHub /\<#[0-9]\+\>/ contained
syn match gvJira /\<[A-Z]\+-[0-9]\+\>/ contained
hi def link gvDate Number
hi def link gvSha Identifier
hi def link gvTag Constant
hi def link gvGitHub Label
hi def link gvJira Label
hi def link gvMeta Conditional
hi def link gvAuthor String

syn match gvAdded "^\W*\zsA\t.*"
syn match gvDeleted "^\W*\zsD\t.*"
hi def link gvAdded diffAdded
hi def link gvDeleted diffRemoved

syn match diffAdded "^+.*"
syn match diffRemoved "^-.*"
syn match diffLine "^@.*"
syn match diffFile "^diff\>.*"
syn match diffFile "^+++ .*"
syn match diffNewFile "^--- .*"
hi def link diffFile Type
hi def link diffNewFile diffFile
hi def link diffAdded Identifier
hi def link diffRemoved Special
hi def link diffFile Type
hi def link diffLine Statement
function! s:gdiff()
let sha = gv#sha()
if len(sha)
tabnew
execute 'e '.g:currBufferForGv
execute 'Gedit '.sha
call search('^diff --git.*\sb/\S*'.g:currBufferForGv.'\s*$')
normal o
" execute 'Gdiff '.sha
wincmd j
q
nmap q :wincmd o<cr>:q<cr>gt
wincmd l
nmap q :wincmd o<cr>:q<cr>gt
wincmd h
endif
endfunction

function! s:maps()
nnoremap <silent> <buffer> q :$wincmd w <bar> close<cr>
nnoremap <silent> <buffer> <nowait> gq :$wincmd w <bar> close<cr>
nnoremap <silent> <buffer> gb :call <sid>gbrowse()<cr>
nnoremap <silent> <buffer> <cr> :call <sid>open(0)<cr>
nnoremap <silent> <buffer> gd :call <sid>gdiff()<cr>
nnoremap <silent> <buffer> D :call <sid>gdiff()<cr>
nnoremap <silent> <buffer> o :call <sid>open(0)<cr>
nnoremap <silent> <buffer> O :call <sid>open(0, 1)<cr>
xnoremap <silent> <buffer> <cr> :<c-u>call <sid>open(1)<cr>
Expand Down Expand Up @@ -211,19 +192,26 @@ function! s:setup(git_dir, git_origin)
let b:git_dir = a:git_dir
endfunction

function! s:disableDimInactive()
if exists(':DimInactiveBufferOff')
DimInactiveBufferOff
endif
endfunction

function! s:scratch()
setlocal buftype=nofile bufhidden=wipe noswapfile nomodeline
endfunction

function! s:fill(cmd)
setlocal modifiable
%delete _
silent execute 'read' escape('!'.a:cmd, '%')
normal! gg"_dd
setlocal nomodifiable
endfunction

function! s:tracked(fugitive_repo, file)
call system(a:fugitive_repo.git_command('ls-files', '--error-unmatch', a:file))
call system(FugitiveShellCommand(['ls-files', '--error-unmatch', a:file]))
return !v:shell_error
endfunction

Expand All @@ -239,15 +227,15 @@ function! s:log_opts(fugitive_repo, bang, visual, line1, line2)
if a:visual || a:bang
let current = expand('%')
call s:check_buffer(a:fugitive_repo, current)
return a:visual ? [printf('-L%d,%d:%s', a:line1, a:line2, current)] : ['--follow', '--', current]
return a:visual ? [[printf('-L%d,%d:%s', a:line1, a:line2, current)], []] : [['--follow'], ['--', current]]
endif
return ['--graph']
return [['--graph'], []]
endfunction

function! s:list(fugitive_repo, log_opts)
let default_opts = ['--color=never', '--date=short', '--format=%cd %h%d %s (%an)']
let git_args = ['log'] + default_opts + a:log_opts
let git_log_cmd = call(a:fugitive_repo.git_command, git_args, a:fugitive_repo)
let git_log_cmd = FugitiveShellCommand(git_args, a:fugitive_repo)

let repo_short_name = fnamemodify(substitute(a:fugitive_repo.dir(), '[\\/]\.git[\\/]\?$', '', ''), ':t')
let bufname = repo_short_name.' '.join(a:log_opts)
Expand All @@ -256,13 +244,13 @@ function! s:list(fugitive_repo, log_opts)
call s:fill(git_log_cmd)
setlocal nowrap tabstop=8 cursorline iskeyword+=#

if !exists(':Gbrowse')
if !exists(':GBrowse')
doautocmd <nomodeline> User Fugitive
endif
call s:maps()
call s:syntax()
setf GV
redraw
echo 'o: open split / O: open tab / gb: Gbrowse / q: quit'
echo 'o: open split / O: open tab / gb: GBrowse / q: quit'
endfunction

function! s:trim(arg)
Expand All @@ -287,14 +275,24 @@ function! gv#shellwords(arg)
return words
endfunction

function! s:split_pathspec(args)
let split = index(a:args, '--')
if split < 0
return [a:args, []]
elseif split == 0
return [[], a:args]
endif
return [a:args[0:split-1], a:args[split:]]
endfunction

function! s:gl(buf, visual)
if !exists(':Gllog')
return
endif
tab split
silent execute a:visual ? "'<,'>" : "" 'Gllog'
call setloclist(0, insert(getloclist(0), {'bufnr': a:buf}, 0))
b #
noautocmd b #
lopen
xnoremap <buffer> o :call <sid>gld()<cr>
nnoremap <buffer> o <cr><c-w><c-w>
Expand All @@ -317,6 +315,7 @@ function! s:gld() range
endfunction

function! s:gv(bang, visual, line1, line2, args) abort
let g:currBufferForGv = expand('%')
if !exists('g:loaded_fugitive')
return s:warn('fugitive not found')
endif
Expand All @@ -341,7 +340,9 @@ function! s:gv(bang, visual, line1, line2, args) abort
call s:check_buffer(fugitive_repo, expand('%'))
call s:gl(bufnr(''), a:visual)
else
let log_opts = extend(gv#shellwords(a:args), s:log_opts(fugitive_repo, a:bang, a:visual, a:line1, a:line2))
let [opts1, paths1] = s:log_opts(fugitive_repo, a:bang, a:visual, a:line1, a:line2)
let [opts2, paths2] = s:split_pathspec(gv#shellwords(a:args))
let log_opts = opts1 + opts2 + paths1 + paths2
call s:setup(git_dir, fugitive_repo.config('remote.origin.url'))
call s:list(fugitive_repo, log_opts)
call FugitiveDetect(@#)
Expand Down
39 changes: 39 additions & 0 deletions syntax/GV.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
if exists("b:current_syntax")
finish
endif

syn clear
syn match gvInfo /^[^0-9]*\zs[0-9-]\+\s\+[a-f0-9]\+ / contains=gvDate,gvSha nextgroup=gvMessage,gvMeta
syn match gvDate /\S\+ / contained
syn match gvSha /[a-f0-9]\{6,}/ contained
syn match gvMessage /.* \ze(.\{-})$/ contained contains=gvTag,gvGitHub,gvJira nextgroup=gvAuthor
syn match gvAuthor /.*$/ contained
syn match gvMeta /([^)]\+) / contained contains=gvTag nextgroup=gvMessage
syn match gvTag /(tag:[^)]\+)/ contained
syn match gvGitHub /\<#[0-9]\+\>/ contained
syn match gvJira /\<[A-Z]\+-[0-9]\+\>/ contained
hi def link gvDate Number
hi def link gvSha Identifier
hi def link gvTag Constant
hi def link gvGitHub Label
hi def link gvJira Label
hi def link gvMeta Conditional
hi def link gvAuthor String

syn match gvAdded "^\W*\zsA\t.*"
syn match gvDeleted "^\W*\zsD\t.*"
hi def link gvAdded diffAdded
hi def link gvDeleted diffRemoved

syn match diffAdded "^+.*"
syn match diffRemoved "^-.*"
syn match diffLine "^@.*"
syn match diffFile "^diff\>.*"
syn match diffFile "^+++ .*"
syn match diffNewFile "^--- .*"
hi def link diffFile Type
hi def link diffNewFile diffFile
hi def link diffAdded Identifier
hi def link diffRemoved Special
hi def link diffFile Type
hi def link diffLine Statement
2 changes: 2 additions & 0 deletions test/gv.vader
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Execute (Test gv#shellwords):
AssertEqual ['foo " bar'], gv#shellwords('"foo \" bar"')
AssertEqual ['foo " bar', 'baz'], gv#shellwords("'foo \" bar' baz")
AssertEqual ['foo', 'bar baz'], gv#shellwords("'foo' 'bar baz'")
AssertEqual ['--'], gv#shellwords('--')
AssertEqual ['--'], gv#shellwords('"--"')

Execute (Test gv#sha):
AssertEqual '33d2a88', gv#sha('* 2016-06-18 33d2a88 Let fugitive add buffer-local Git command to GV buffer (Junegunn Choi)')
Expand Down