Update vim-gitgutter.
This commit is contained in:
parent
2538a00dff
commit
ca2bc6ca9f
11 changed files with 254 additions and 118 deletions
|
@ -18,6 +18,7 @@ Features:
|
|||
* Stage partial hunks.
|
||||
* Provides a hunk text object.
|
||||
* Diffs against index (default) or any commit.
|
||||
* Heeds git's "assume unchanged" bit.
|
||||
* Allows folding all unchanged text.
|
||||
* Provides fold text showing whether folded lines have been changed.
|
||||
* Can load all hunk locations into quickfix list or the current window's location list.
|
||||
|
@ -238,6 +239,11 @@ Finally, you can force vim-gitgutter to update its signs across all visible buff
|
|||
See the customisation section below for how to change the defaults.
|
||||
|
||||
|
||||
### Vimdiff
|
||||
|
||||
Use the `GitGutterDiffOrig` command to open a vimdiff view of the current buffer, respecting `g:gitgutter_diff_relative_to` and `:gitgutter_diff_base`.
|
||||
|
||||
|
||||
### Folding
|
||||
|
||||
Use the `GitGutterFold` command to fold all unchanged lines, leaving just the hunks visible. Use `zr` to unfold 3 lines of context above and below a hunk.
|
||||
|
@ -299,6 +305,7 @@ You can customise:
|
|||
* Whether to clobber or preserve non-gitgutter signs
|
||||
* The priority of gitgutter's signs.
|
||||
* Whether to use a floating/popup window for hunk previews
|
||||
* The appearance of a floating/popup window for hunk previews
|
||||
* Whether to populate the quickfix list or a location list with all hunks
|
||||
|
||||
Please note that vim-gitgutter won't override any colours or highlights you've set in your colorscheme.
|
||||
|
@ -519,6 +526,11 @@ let g:gitgutter_async = 0
|
|||
Add `let g:gitgutter_preview_win_floating = 1` to your `~/.vimrc`. Note that on Vim this prevents you staging (partial) hunks via the preview window.
|
||||
|
||||
|
||||
#### The appearance of a floating/popup window for hunk previews
|
||||
|
||||
Set `g:gitgutter_floating_window_options` to a dictionary of the options you want. This dictionary is passed directly to `popup_create()` (Vim) / `nvim_open_win()` (Neovim).
|
||||
|
||||
|
||||
#### To load all hunks into the current window's location list instead of the quickfix list
|
||||
|
||||
Add `let g:gitgutter_use_location_list = 1` to your `~/.vimrc`.
|
||||
|
|
|
@ -21,6 +21,10 @@ endfunction
|
|||
function! gitgutter#process_buffer(bufnr, force) abort
|
||||
" NOTE a:bufnr is not necessarily the current buffer.
|
||||
|
||||
if gitgutter#utility#getbufvar(a:bufnr, 'enabled', -1) == -1
|
||||
call gitgutter#utility#setbufvar(a:bufnr, 'enabled', g:gitgutter_enabled)
|
||||
endif
|
||||
|
||||
if gitgutter#utility#is_active(a:bufnr)
|
||||
|
||||
if has('patch-7.4.1559')
|
||||
|
@ -40,6 +44,8 @@ function! gitgutter#process_buffer(bufnr, force) abort
|
|||
let diff = gitgutter#diff#run_diff(a:bufnr, g:gitgutter_diff_relative_to, 0)
|
||||
catch /gitgutter not tracked/
|
||||
call gitgutter#debug#log('Not tracked: '.gitgutter#utility#file(a:bufnr))
|
||||
catch /gitgutter assume unchanged/
|
||||
call gitgutter#debug#log('Assume unchanged: '.gitgutter#utility#file(a:bufnr))
|
||||
catch /gitgutter diff failed/
|
||||
call gitgutter#debug#log('Diff failed: '.gitgutter#utility#file(a:bufnr))
|
||||
call gitgutter#hunk#reset(a:bufnr)
|
||||
|
@ -55,22 +61,28 @@ endfunction
|
|||
|
||||
|
||||
function! gitgutter#disable() abort
|
||||
" get list of all buffers (across all tabs)
|
||||
for bufnr in range(1, bufnr('$') + 1)
|
||||
if buflisted(bufnr)
|
||||
let file = expand('#'.bufnr.':p')
|
||||
if !empty(file)
|
||||
call s:clear(bufnr)
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
|
||||
call s:toggle_each_buffer(0)
|
||||
let g:gitgutter_enabled = 0
|
||||
endfunction
|
||||
|
||||
function! gitgutter#enable() abort
|
||||
call s:toggle_each_buffer(1)
|
||||
let g:gitgutter_enabled = 1
|
||||
call gitgutter#all(1)
|
||||
endfunction
|
||||
|
||||
function s:toggle_each_buffer(enable)
|
||||
for bufnr in range(1, bufnr('$') + 1)
|
||||
if buflisted(bufnr)
|
||||
let file = expand('#'.bufnr.':p')
|
||||
if !empty(file)
|
||||
if a:enable
|
||||
call gitgutter#buffer_enable(bufnr)
|
||||
else
|
||||
call gitgutter#buffer_disable(bufnr)
|
||||
end
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! gitgutter#toggle() abort
|
||||
|
@ -82,23 +94,24 @@ function! gitgutter#toggle() abort
|
|||
endfunction
|
||||
|
||||
|
||||
function! gitgutter#buffer_disable() abort
|
||||
let bufnr = bufnr('')
|
||||
function! gitgutter#buffer_disable(...) abort
|
||||
let bufnr = a:0 ? a:1 : bufnr('')
|
||||
call gitgutter#utility#setbufvar(bufnr, 'enabled', 0)
|
||||
call s:clear(bufnr)
|
||||
endfunction
|
||||
|
||||
function! gitgutter#buffer_enable() abort
|
||||
let bufnr = bufnr('')
|
||||
function! gitgutter#buffer_enable(...) abort
|
||||
let bufnr = a:0 ? a:1 : bufnr('')
|
||||
call gitgutter#utility#setbufvar(bufnr, 'enabled', 1)
|
||||
call gitgutter#process_buffer(bufnr, 1)
|
||||
endfunction
|
||||
|
||||
function! gitgutter#buffer_toggle() abort
|
||||
if gitgutter#utility#getbufvar(bufnr(''), 'enabled', 1)
|
||||
call gitgutter#buffer_disable()
|
||||
function! gitgutter#buffer_toggle(...) abort
|
||||
let bufnr = a:0 ? a:1 : bufnr('')
|
||||
if gitgutter#utility#getbufvar(bufnr, 'enabled', 1)
|
||||
call gitgutter#buffer_disable(bufnr)
|
||||
else
|
||||
call gitgutter#buffer_enable()
|
||||
call gitgutter#buffer_enable(bufnr)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
@ -222,3 +235,31 @@ function! gitgutter#quickfix(current_file)
|
|||
call setloclist(0, locations)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
function! gitgutter#difforig()
|
||||
let bufnr = bufnr('')
|
||||
let path = gitgutter#utility#repo_path(bufnr, 1)
|
||||
let filetype = &filetype
|
||||
|
||||
vertical new
|
||||
set buftype=nofile
|
||||
let &filetype = filetype
|
||||
|
||||
if g:gitgutter_diff_relative_to ==# 'index'
|
||||
let index_name = gitgutter#utility#get_diff_base(bufnr).':'.path
|
||||
let cmd = gitgutter#utility#cd_cmd(bufnr,
|
||||
\ g:gitgutter_git_executable.' '.g:gitgutter_git_args.' --no-pager show '.index_name
|
||||
\ )
|
||||
" NOTE: this uses &shell to execute cmd. Perhaps we should use instead
|
||||
" gitgutter#utility's use_known_shell() / restore_shell() functions.
|
||||
silent! execute "read ++edit !" cmd
|
||||
else
|
||||
silent! execute "read ++edit" path
|
||||
endif
|
||||
|
||||
0d_
|
||||
diffthis
|
||||
wincmd p
|
||||
diffthis
|
||||
endfunction
|
||||
|
|
|
@ -77,6 +77,10 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
|
|||
throw 'gitgutter not tracked'
|
||||
endif
|
||||
|
||||
if gitgutter#utility#repo_path(a:bufnr, 0) == -3
|
||||
throw 'gitgutter assume unchanged'
|
||||
endif
|
||||
|
||||
" Wrap compound commands in parentheses to make Windows happy.
|
||||
" bash doesn't mind the parentheses.
|
||||
let cmd = '('
|
||||
|
|
|
@ -150,12 +150,6 @@ function! s:lcs(s1, s2)
|
|||
return a:s1[endindex - maxlength + 1 : endindex]
|
||||
endfunction
|
||||
|
||||
if $VIM_GITGUTTER_TEST
|
||||
function! gitgutter#diff_highlight#lcs(s1, s2)
|
||||
return s:lcs(a:s1, a:s2)
|
||||
endfunction
|
||||
endif
|
||||
|
||||
|
||||
" Returns 0-based index of last character of common prefix
|
||||
" If there is no common prefix, returns -1.
|
||||
|
@ -175,12 +169,6 @@ function! s:common_prefix(a, b)
|
|||
return i
|
||||
endfunction
|
||||
|
||||
if $VIM_GITGUTTER_TEST
|
||||
function! gitgutter#diff_highlight#common_prefix(a, b)
|
||||
return s:common_prefix(a:a, a:b)
|
||||
endfunction
|
||||
endif
|
||||
|
||||
|
||||
" Returns 0-based indices of start of common suffix
|
||||
"
|
||||
|
@ -199,12 +187,6 @@ function! s:common_suffix(a, b, start)
|
|||
return [sa+1, sb+1]
|
||||
endfunction
|
||||
|
||||
if $VIM_GITGUTTER_TEST
|
||||
function! gitgutter#diff_highlight#common_suffix(a, b, start)
|
||||
return s:common_suffix(a:a, a:b, a:start)
|
||||
endfunction
|
||||
endif
|
||||
|
||||
|
||||
" Split a string on another string.
|
||||
" Assumes 1 occurrence of the delimiter.
|
||||
|
@ -217,9 +199,3 @@ function! s:split(str, delimiter)
|
|||
|
||||
return [a:str[:i-1], a:str[i+len(a:delimiter):]]
|
||||
endfunction
|
||||
|
||||
if $VIM_GITGUTTER_TEST
|
||||
function! gitgutter#diff_highlight#split(str, delimiter)
|
||||
return s:split(a:str, a:delimiter)
|
||||
endfunction
|
||||
endif
|
||||
|
|
|
@ -175,12 +175,12 @@ function! s:define_sign_line_highlights() abort
|
|||
sign define GitGutterLineRemovedAboveAndBelow linehl=GitGutterDeleteLine
|
||||
sign define GitGutterLineModifiedRemoved linehl=GitGutterChangeDeleteLine
|
||||
else
|
||||
sign define GitGutterLineAdded linehl=
|
||||
sign define GitGutterLineModified linehl=
|
||||
sign define GitGutterLineRemoved linehl=
|
||||
sign define GitGutterLineRemovedFirstLine linehl=
|
||||
sign define GitGutterLineRemovedAboveAndBelow linehl=
|
||||
sign define GitGutterLineModifiedRemoved linehl=
|
||||
sign define GitGutterLineAdded linehl=NONE
|
||||
sign define GitGutterLineModified linehl=NONE
|
||||
sign define GitGutterLineRemoved linehl=NONE
|
||||
sign define GitGutterLineRemovedFirstLine linehl=NONE
|
||||
sign define GitGutterLineRemovedAboveAndBelow linehl=NONE
|
||||
sign define GitGutterLineModifiedRemoved linehl=NONE
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
@ -195,12 +195,12 @@ function! s:define_sign_linenr_highlights() abort
|
|||
sign define GitGutterLineRemovedAboveAndBelow numhl=GitGutterDeleteLineNr
|
||||
sign define GitGutterLineModifiedRemoved numhl=GitGutterChangeDeleteLineNr
|
||||
else
|
||||
sign define GitGutterLineAdded numhl=
|
||||
sign define GitGutterLineModified numhl=
|
||||
sign define GitGutterLineRemoved numhl=
|
||||
sign define GitGutterLineRemovedFirstLine numhl=
|
||||
sign define GitGutterLineRemovedAboveAndBelow numhl=
|
||||
sign define GitGutterLineModifiedRemoved numhl=
|
||||
sign define GitGutterLineAdded numhl=NONE
|
||||
sign define GitGutterLineModified numhl=NONE
|
||||
sign define GitGutterLineRemoved numhl=NONE
|
||||
sign define GitGutterLineRemovedFirstLine numhl=NONE
|
||||
sign define GitGutterLineRemovedAboveAndBelow numhl=NONE
|
||||
sign define GitGutterLineModifiedRemoved numhl=NONE
|
||||
endif
|
||||
catch /E475/
|
||||
endtry
|
||||
|
|
|
@ -382,12 +382,6 @@ function! s:fix_file_references(filepath, hunk_diff)
|
|||
return join(lines, "\n")."\n"
|
||||
endfunction
|
||||
|
||||
if $VIM_GITGUTTER_TEST
|
||||
function! gitgutter#hunk#fix_file_references(filepath, hunk_diff)
|
||||
return s:fix_file_references(a:filepath, a:hunk_diff)
|
||||
endfunction
|
||||
endif
|
||||
|
||||
|
||||
function! s:adjust_hunk_summary(hunk_diff) abort
|
||||
let line_adjustment = s:line_adjustment_for_current_hunk()
|
||||
|
@ -431,14 +425,7 @@ function! s:open_hunk_preview_window()
|
|||
|
||||
let buf = nvim_create_buf(v:false, v:false)
|
||||
" Set default width and height for now.
|
||||
let s:winid = nvim_open_win(buf, v:false, {
|
||||
\ 'relative': 'cursor',
|
||||
\ 'row': 1,
|
||||
\ 'col': 0,
|
||||
\ 'width': 42,
|
||||
\ 'height': &previewheight,
|
||||
\ 'style': 'minimal'
|
||||
\ })
|
||||
let s:winid = nvim_open_win(buf, v:false, g:gitgutter_floating_window_options)
|
||||
call nvim_buf_set_option(buf, 'filetype', 'diff')
|
||||
call nvim_buf_set_option(buf, 'buftype', 'acwrite')
|
||||
call nvim_buf_set_option(buf, 'bufhidden', 'delete')
|
||||
|
@ -461,16 +448,11 @@ function! s:open_hunk_preview_window()
|
|||
endif
|
||||
|
||||
if exists('*popup_create')
|
||||
let opts = {
|
||||
\ 'line': 'cursor+1',
|
||||
\ 'col': 'cursor',
|
||||
\ 'moved': 'any',
|
||||
\ }
|
||||
if g:gitgutter_close_preview_on_escape
|
||||
let opts.filter = function('s:close_popup_on_escape')
|
||||
let g:gitgutter_floating_window_options.filter = function('s:close_popup_on_escape')
|
||||
endif
|
||||
|
||||
let s:winid = popup_create('', opts)
|
||||
let s:winid = popup_create('', g:gitgutter_floating_window_options)
|
||||
|
||||
call setbufvar(winbufnr(s:winid), '&filetype', 'diff')
|
||||
|
||||
|
@ -478,6 +460,10 @@ function! s:open_hunk_preview_window()
|
|||
endif
|
||||
endif
|
||||
|
||||
if exists('&previewpopup')
|
||||
let [previewpopup, &previewpopup] = [&previewpopup, '']
|
||||
endif
|
||||
|
||||
" Specifying where to open the preview window can lead to the cursor going
|
||||
" to an unexpected window when the preview window is closed (#769).
|
||||
silent! noautocmd execute g:gitgutter_preview_win_location 'pedit gitgutter://hunk-preview'
|
||||
|
@ -496,6 +482,10 @@ function! s:open_hunk_preview_window()
|
|||
" Ensure cursor goes to the expected window.
|
||||
nnoremap <buffer> <silent> <Esc> :<C-U>wincmd p<Bar>pclose<CR>
|
||||
endif
|
||||
|
||||
if exists('&previewpopup')
|
||||
let &previewpopup=previewpopup
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
|
@ -515,7 +505,7 @@ function! s:populate_hunk_preview_window(header, body)
|
|||
|
||||
if g:gitgutter_preview_win_floating
|
||||
if exists('*nvim_open_win')
|
||||
let height = min([body_length, &previewheight])
|
||||
let height = min([body_length, g:gitgutter_floating_window_options.height])
|
||||
|
||||
" Assumes cursor is not in previewing window.
|
||||
call nvim_buf_set_var(winbufnr(s:winid), 'hunk_header', a:header)
|
||||
|
|
|
@ -48,8 +48,7 @@ endfunction
|
|||
" Returns truthy when the buffer's file should be processed; and falsey when it shouldn't.
|
||||
" This function does not and should not make any system calls.
|
||||
function! gitgutter#utility#is_active(bufnr) abort
|
||||
return g:gitgutter_enabled &&
|
||||
\ gitgutter#utility#getbufvar(a:bufnr, 'enabled', 1) &&
|
||||
return gitgutter#utility#getbufvar(a:bufnr, 'enabled') &&
|
||||
\ !pumvisible() &&
|
||||
\ s:is_file_buffer(a:bufnr) &&
|
||||
\ s:exists_file(a:bufnr) &&
|
||||
|
@ -109,6 +108,7 @@ endfunction
|
|||
" * non-empty string - path
|
||||
" * -1 - pending
|
||||
" * -2 - not tracked by git
|
||||
" * -3 - assume unchanged
|
||||
function! gitgutter#utility#repo_path(bufnr, shellesc) abort
|
||||
let p = gitgutter#utility#getbufvar(a:bufnr, 'path', '')
|
||||
return a:shellesc ? gitgutter#utility#shellescape(p) : p
|
||||
|
@ -117,9 +117,14 @@ endfunction
|
|||
|
||||
let s:set_path_handler = {}
|
||||
|
||||
function! s:set_path_handler.out(buffer, path) abort
|
||||
let path = s:strip_trailing_new_line(a:path)
|
||||
function! s:set_path_handler.out(buffer, listing) abort
|
||||
let listing = s:strip_trailing_new_line(a:listing)
|
||||
let [status, path] = [listing[0], listing[2:]]
|
||||
if status =~# '[a-z]'
|
||||
call gitgutter#utility#setbufvar(a:buffer, 'path', -3)
|
||||
else
|
||||
call gitgutter#utility#setbufvar(a:buffer, 'path', path)
|
||||
endif
|
||||
|
||||
if type(self.continuation) == type(function('tr'))
|
||||
call self.continuation()
|
||||
|
@ -141,9 +146,13 @@ function! gitgutter#utility#set_repo_path(bufnr, continuation) abort
|
|||
" * non-empty string - path
|
||||
" * -1 - pending
|
||||
" * -2 - not tracked by git
|
||||
" * -3 - assume unchanged
|
||||
|
||||
call gitgutter#utility#setbufvar(a:bufnr, 'path', -1)
|
||||
let cmd = gitgutter#utility#cd_cmd(a:bufnr, g:gitgutter_git_executable.' '.g:gitgutter_git_args.' ls-files --error-unmatch --full-name -z -- '.gitgutter#utility#shellescape(s:filename(a:bufnr)))
|
||||
let cmd = gitgutter#utility#cd_cmd(a:bufnr,
|
||||
\ g:gitgutter_git_executable.' '.g:gitgutter_git_args.
|
||||
\ ' ls-files -v --error-unmatch --full-name -z -- '.
|
||||
\ gitgutter#utility#shellescape(s:filename(a:bufnr)))
|
||||
|
||||
if g:gitgutter_async && gitgutter#async#available() && !has('vim_starting')
|
||||
let handler = copy(s:set_path_handler)
|
||||
|
@ -152,11 +161,19 @@ function! gitgutter#utility#set_repo_path(bufnr, continuation) abort
|
|||
return 'async'
|
||||
endif
|
||||
|
||||
let path = gitgutter#utility#system(cmd)
|
||||
let listing = gitgutter#utility#system(cmd)
|
||||
|
||||
if v:shell_error
|
||||
call gitgutter#utility#setbufvar(a:bufnr, 'path', -2)
|
||||
return
|
||||
endif
|
||||
|
||||
let listing = s:strip_trailing_new_line(listing)
|
||||
let [status, path] = [listing[0], listing[2:]]
|
||||
if status =~# '[a-z]'
|
||||
call gitgutter#utility#setbufvar(a:bufnr, 'path', -3)
|
||||
else
|
||||
call gitgutter#utility#setbufvar(a:bufnr, 'path', s:strip_trailing_new_line(path))
|
||||
call gitgutter#utility#setbufvar(a:bufnr, 'path', path)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
|
|
@ -93,6 +93,15 @@ Commands for turning vim-gitgutter on and off:~
|
|||
*gitgutter-:GitGutterToggle*
|
||||
:GitGutterToggle Toggle vim-gitgutter on or off for all buffers.
|
||||
|
||||
*gitgutter-:GitGutterBufferDisable*
|
||||
:GitGutterBufferDisable Turn vim-gitgutter off for current buffer.
|
||||
|
||||
*gitgutter-:GitGutterBufferEnable*
|
||||
:GitGutterBufferEnable Turn vim-gitgutter on for current buffer.
|
||||
|
||||
*gitgutter-:GitGutterBufferToggle*
|
||||
:GitGutterBufferToggle Toggle vim-gitgutter on or off for current buffer.
|
||||
|
||||
*gitgutter-:GitGutter*
|
||||
:GitGutter Update signs for the current buffer. You shouldn't
|
||||
need to run this.
|
||||
|
@ -212,6 +221,12 @@ Commands for folds:~
|
|||
:GitGutterFold Fold all unchanged lines. Execute again to undo.
|
||||
|
||||
|
||||
Other commands:~
|
||||
|
||||
*gitgutter-:GitGutterDiffOrig*
|
||||
:GitGutterDiffOrig Similar to |:DiffOrig| but shows gitgutter's diff.
|
||||
|
||||
|
||||
===============================================================================
|
||||
AUTOCOMMANDS *gitgutter-autocommands*
|
||||
|
||||
|
@ -348,6 +363,7 @@ Hunk jumping:~
|
|||
Hunk previews:~
|
||||
|
||||
|g:gitgutter_preview_win_floating|
|
||||
|g:gitgutter_floating_window_options|
|
||||
|g:gitgutter_close_preview_on_escape|
|
||||
|
||||
Terminal:~
|
||||
|
@ -508,6 +524,29 @@ Whether to use floating/popup windows for hunk previews. Note that if you use
|
|||
popup windows on Vim you will not be able to stage partial hunks via the
|
||||
preview window.
|
||||
|
||||
*g:gitgutter_floating_window_options*
|
||||
Default:
|
||||
>
|
||||
" Vim
|
||||
{
|
||||
\ 'line': 'cursor+1',
|
||||
\ 'col': 'cursor',
|
||||
\ 'moved': 'any'
|
||||
}
|
||||
|
||||
" Neovim
|
||||
{
|
||||
\ 'relative': 'cursor',
|
||||
\ 'row': 1,
|
||||
\ 'col': 0,
|
||||
\ 'width': 42,
|
||||
\ 'height': &previewheight,
|
||||
\ 'style': 'minimal'
|
||||
}
|
||||
<
|
||||
This dictionary is passed directly to |popup_create()| (Vim) or
|
||||
|nvim_open_win()| (Neovim).
|
||||
|
||||
*g:gitgutter_close_preview_on_escape*
|
||||
Default: 0
|
||||
|
||||
|
|
|
@ -24,9 +24,22 @@ endfunction
|
|||
let g:gitgutter_preview_win_location = get(g:, 'gitgutter_preview_win_location', 'bo')
|
||||
if exists('*nvim_open_win')
|
||||
let g:gitgutter_preview_win_floating = get(g:, 'gitgutter_preview_win_floating', 1)
|
||||
let g:gitgutter_floating_window_options = get(g:, 'gitgutter_floating_window_options', {
|
||||
\ 'relative': 'cursor',
|
||||
\ 'row': 1,
|
||||
\ 'col': 0,
|
||||
\ 'width': 42,
|
||||
\ 'height': &previewheight,
|
||||
\ 'style': 'minimal'
|
||||
\ })
|
||||
else
|
||||
let default = exists('&previewpopup') ? !empty(&previewpopup) : 0
|
||||
let g:gitgutter_preview_win_floating = get(g:, 'gitgutter_preview_win_floating', default)
|
||||
let g:gitgutter_floating_window_options = get(g:, 'gitgutter_floating_window_options', {
|
||||
\ 'line': 'cursor+1',
|
||||
\ 'col': 'cursor',
|
||||
\ 'moved': 'any'
|
||||
\ })
|
||||
endif
|
||||
let g:gitgutter_enabled = get(g:, 'gitgutter_enabled', 1)
|
||||
if exists('*sign_unplace')
|
||||
|
@ -121,6 +134,8 @@ command! -bar GitGutterBufferToggle call gitgutter#buffer_toggle()
|
|||
command! -bar GitGutterQuickFix call gitgutter#quickfix(0)
|
||||
command! -bar GitGutterQuickFixCurrentFile call gitgutter#quickfix(1)
|
||||
|
||||
command! -bar GitGutterDiffOrig call gitgutter#difforig()
|
||||
|
||||
" }}}
|
||||
|
||||
" Line highlights {{{
|
||||
|
@ -248,6 +263,10 @@ function! GitGutterCursorHold(timer)
|
|||
execute 'doautocmd' s:nomodeline 'gitgutter CursorHold'
|
||||
endfunction
|
||||
|
||||
function! s:next_tick(cmd)
|
||||
call timer_start(1, {-> execute(a:cmd)})
|
||||
endfunction
|
||||
|
||||
" Autocommands {{{
|
||||
|
||||
augroup gitgutter
|
||||
|
@ -264,9 +283,9 @@ augroup gitgutter
|
|||
|
||||
autocmd CursorHold,CursorHoldI * call gitgutter#process_buffer(bufnr(''), 0)
|
||||
if exists('*timer_start') && has('lambda')
|
||||
autocmd FileChangedShellPost * call timer_start(1, {-> gitgutter#process_buffer(bufnr(''), 1)})
|
||||
autocmd FileChangedShellPost * call s:next_tick("call gitgutter#process_buffer(+".expand('<abuf>').", 1)")
|
||||
else
|
||||
autocmd FileChangedShellPost * call gitgutter#process_buffer(bufnr(''), 1)
|
||||
autocmd FileChangedShellPost * call gitgutter#process_buffer(+expand('<abuf>'), 1)
|
||||
endif
|
||||
|
||||
" Ensure that all buffers are processed when opening vim with multiple files, e.g.:
|
||||
|
|
0
sources_non_forked/vim-gitgutter/test/test
Normal file → Executable file
0
sources_non_forked/vim-gitgutter/test/test
Normal file → Executable file
|
@ -205,6 +205,20 @@ function Test_filename_with_square_brackets()
|
|||
endfunction
|
||||
|
||||
|
||||
function Test_filename_with_space()
|
||||
call system('touch fix\ ture.txt && git add fix\ ture.txt')
|
||||
edit fix\ ture.txt
|
||||
normal ggo*
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
let expected = [
|
||||
\ {'lnum': 1, 'name': 'GitGutterLineAdded'},
|
||||
\ {'lnum': 2, 'name': 'GitGutterLineAdded'}
|
||||
\ ]
|
||||
call s:assert_signs(expected, 'fix\ ture.txt')
|
||||
endfunction
|
||||
|
||||
|
||||
function Test_filename_leading_dash()
|
||||
call system('touch -- -fixture.txt && git add -- -fixture.txt')
|
||||
edit -fixture.txt
|
||||
|
@ -835,6 +849,9 @@ endfunction
|
|||
|
||||
|
||||
function Test_fix_file_references()
|
||||
let sid = matchstr(execute('filter autoload/gitgutter/hunk.vim scriptnames'), '\d\+')
|
||||
let FixFileReferences = function("<SNR>".sid."_fix_file_references")
|
||||
|
||||
" No special characters
|
||||
let hunk_diff = join([
|
||||
\ 'diff --git a/fixture.txt b/fixture.txt',
|
||||
|
@ -855,7 +872,7 @@ function Test_fix_file_references()
|
|||
\ '+x'
|
||||
\ ], "\n")."\n"
|
||||
|
||||
call assert_equal(expected, gitgutter#hunk#fix_file_references(filepath, hunk_diff))
|
||||
call assert_equal(expected, FixFileReferences(filepath, hunk_diff))
|
||||
|
||||
" diff.mnemonicPrefix; spaces in filename
|
||||
let hunk_diff = join([
|
||||
|
@ -877,7 +894,7 @@ function Test_fix_file_references()
|
|||
\ '+x'
|
||||
\ ], "\n")."\n"
|
||||
|
||||
call assert_equal(expected, gitgutter#hunk#fix_file_references(filepath, hunk_diff))
|
||||
call assert_equal(expected, FixFileReferences(filepath, hunk_diff))
|
||||
|
||||
" Backslashes in filename; quotation marks
|
||||
let hunk_diff = join([
|
||||
|
@ -899,7 +916,7 @@ function Test_fix_file_references()
|
|||
\ '+x'
|
||||
\ ], "\n")."\n"
|
||||
|
||||
call assert_equal(expected, gitgutter#hunk#fix_file_references(filepath, hunk_diff))
|
||||
call assert_equal(expected, FixFileReferences(filepath, hunk_diff))
|
||||
endfunction
|
||||
|
||||
|
||||
|
@ -975,39 +992,45 @@ endfunction
|
|||
|
||||
|
||||
function Test_common_prefix()
|
||||
let sid = matchstr(execute('filter autoload/gitgutter/diff_highlight.vim scriptnames'), '\d\+')
|
||||
let CommonPrefix = function("<SNR>".sid."_common_prefix")
|
||||
|
||||
" zero length
|
||||
call assert_equal(-1, gitgutter#diff_highlight#common_prefix('', 'foo'))
|
||||
call assert_equal(-1, gitgutter#diff_highlight#common_prefix('foo', ''))
|
||||
call assert_equal(-1, CommonPrefix('', 'foo'))
|
||||
call assert_equal(-1, CommonPrefix('foo', ''))
|
||||
" nothing in common
|
||||
call assert_equal(-1, gitgutter#diff_highlight#common_prefix('-abcde', '+pqrst'))
|
||||
call assert_equal(-1, gitgutter#diff_highlight#common_prefix('abcde', 'pqrst'))
|
||||
call assert_equal(-1, CommonPrefix('-abcde', '+pqrst'))
|
||||
call assert_equal(-1, CommonPrefix('abcde', 'pqrst'))
|
||||
" something in common
|
||||
call assert_equal(-1, gitgutter#diff_highlight#common_prefix('-abcde', '+abcpq'))
|
||||
call assert_equal(2, gitgutter#diff_highlight#common_prefix('abcde', 'abcpq'))
|
||||
call assert_equal(0, gitgutter#diff_highlight#common_prefix('abc', 'apq'))
|
||||
call assert_equal(-1, CommonPrefix('-abcde', '+abcpq'))
|
||||
call assert_equal(2, CommonPrefix('abcde', 'abcpq'))
|
||||
call assert_equal(0, CommonPrefix('abc', 'apq'))
|
||||
" everything in common
|
||||
call assert_equal(-1, gitgutter#diff_highlight#common_prefix('-abcde', '+abcde'))
|
||||
call assert_equal(4, gitgutter#diff_highlight#common_prefix('abcde', 'abcde'))
|
||||
call assert_equal(-1, CommonPrefix('-abcde', '+abcde'))
|
||||
call assert_equal(4, CommonPrefix('abcde', 'abcde'))
|
||||
" different lengths
|
||||
call assert_equal(-1, gitgutter#diff_highlight#common_prefix('-abcde', '+abx'))
|
||||
call assert_equal(1, gitgutter#diff_highlight#common_prefix('abcde', 'abx'))
|
||||
call assert_equal(-1, gitgutter#diff_highlight#common_prefix('-abx', '+abcde'))
|
||||
call assert_equal(1, gitgutter#diff_highlight#common_prefix('abx', 'abcde'))
|
||||
call assert_equal(-1, gitgutter#diff_highlight#common_prefix('-abcde', '+abc'))
|
||||
call assert_equal(2, gitgutter#diff_highlight#common_prefix('abcde', 'abc'))
|
||||
call assert_equal(-1, CommonPrefix('-abcde', '+abx'))
|
||||
call assert_equal(1, CommonPrefix('abcde', 'abx'))
|
||||
call assert_equal(-1, CommonPrefix('-abx', '+abcde'))
|
||||
call assert_equal(1, CommonPrefix('abx', 'abcde'))
|
||||
call assert_equal(-1, CommonPrefix('-abcde', '+abc'))
|
||||
call assert_equal(2, CommonPrefix('abcde', 'abc'))
|
||||
endfunction
|
||||
|
||||
|
||||
function Test_common_suffix()
|
||||
let sid = matchstr(execute('filter autoload/gitgutter/diff_highlight.vim scriptnames'), '\d\+')
|
||||
let CommonSuffix = function("<SNR>".sid."_common_suffix")
|
||||
|
||||
" nothing in common
|
||||
call assert_equal([6,6], gitgutter#diff_highlight#common_suffix('-abcde', '+pqrst', 0))
|
||||
call assert_equal([6,6], CommonSuffix('-abcde', '+pqrst', 0))
|
||||
" something in common
|
||||
call assert_equal([3,3], gitgutter#diff_highlight#common_suffix('-abcde', '+pqcde', 0))
|
||||
call assert_equal([3,3], CommonSuffix('-abcde', '+pqcde', 0))
|
||||
" everything in common
|
||||
call assert_equal([5,5], gitgutter#diff_highlight#common_suffix('-abcde', '+abcde', 5))
|
||||
call assert_equal([5,5], CommonSuffix('-abcde', '+abcde', 5))
|
||||
" different lengths
|
||||
call assert_equal([4,2], gitgutter#diff_highlight#common_suffix('-abcde', '+xde', 0))
|
||||
call assert_equal([2,4], gitgutter#diff_highlight#common_suffix('-xde', '+abcde', 0))
|
||||
call assert_equal([4,2], CommonSuffix('-abcde', '+xde', 0))
|
||||
call assert_equal([2,4], CommonSuffix('-xde', '+abcde', 0))
|
||||
endfunction
|
||||
|
||||
|
||||
|
@ -1096,18 +1119,24 @@ endfunction
|
|||
|
||||
|
||||
function Test_lcs()
|
||||
call assert_equal('', gitgutter#diff_highlight#lcs('', 'foo'))
|
||||
call assert_equal('', gitgutter#diff_highlight#lcs('foo', ''))
|
||||
call assert_equal('bar', gitgutter#diff_highlight#lcs('foobarbaz', 'bbart'))
|
||||
call assert_equal('transaction', gitgutter#diff_highlight#lcs('transaction.unexplained_amount', 'amount(transaction)'))
|
||||
let sid = matchstr(execute('filter autoload/gitgutter/diff_highlight.vim scriptnames'), '\d\+')
|
||||
let Lcs = function("<SNR>".sid."_lcs")
|
||||
|
||||
call assert_equal('', Lcs('', 'foo'))
|
||||
call assert_equal('', Lcs('foo', ''))
|
||||
call assert_equal('bar', Lcs('foobarbaz', 'bbart'))
|
||||
call assert_equal('transaction', Lcs('transaction.unexplained_amount', 'amount(transaction)'))
|
||||
endfunction
|
||||
|
||||
|
||||
function Test_split()
|
||||
call assert_equal(['foo', 'baz'], gitgutter#diff_highlight#split('foobarbaz', 'bar'))
|
||||
call assert_equal(['', 'barbaz'], gitgutter#diff_highlight#split('foobarbaz', 'foo'))
|
||||
call assert_equal(['foobar', ''], gitgutter#diff_highlight#split('foobarbaz', 'baz'))
|
||||
call assert_equal(['1', '2'], gitgutter#diff_highlight#split('1~2', '~'))
|
||||
let sid = matchstr(execute('filter autoload/gitgutter/diff_highlight.vim scriptnames'), '\d\+')
|
||||
let Split = function("<SNR>".sid."_split")
|
||||
|
||||
call assert_equal(['foo', 'baz'], Split('foobarbaz', 'bar'))
|
||||
call assert_equal(['', 'barbaz'], Split('foobarbaz', 'foo'))
|
||||
call assert_equal(['foobar', ''], Split('foobarbaz', 'baz'))
|
||||
call assert_equal(['1', '2'], Split('1~2', '~'))
|
||||
endfunction
|
||||
|
||||
|
||||
|
@ -1126,3 +1155,12 @@ function Test_foldtext()
|
|||
call assert_equal(0, gitgutter#fold#is_changed())
|
||||
call assert_equal('+- 3 lines: a', gitgutter#fold#foldtext())
|
||||
endfunction
|
||||
|
||||
|
||||
function Test_assume_unchanged()
|
||||
call system("git update-index --assume-unchanged fixture.txt")
|
||||
unlet b:gitgutter.path " it was already set when fixture.txt was loaded in SetUp()
|
||||
normal ggo*
|
||||
call s:trigger_gitgutter()
|
||||
call s:assert_signs([], 'fixture.txt')
|
||||
endfunction
|
||||
|
|
Loading…
Reference in a new issue