mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-11 04:53:46 -05:00
Warn when cursor not in a hunk.
This commit is contained in:
@@ -156,11 +156,15 @@ function! gitgutter#stage_hunk()
|
||||
" It doesn't make sense to stage a hunk otherwise.
|
||||
silent write
|
||||
|
||||
if empty(gitgutter#hunk#current_hunk())
|
||||
call gitgutter#utility#warn('cursor is not in a hunk')
|
||||
else
|
||||
let diff_for_hunk = gitgutter#diff#generate_diff_for_hunk('stage')
|
||||
call gitgutter#utility#system(gitgutter#utility#command_in_directory_of_file('git apply --cached --unidiff-zero - '), diff_for_hunk)
|
||||
|
||||
" refresh gitgutter's view of buffer
|
||||
silent execute "GitGutter"
|
||||
endif
|
||||
|
||||
silent! call repeat#set("\<Plug>GitGutterStageHunk", -1)<CR>
|
||||
endif
|
||||
@@ -172,11 +176,15 @@ function! gitgutter#revert_hunk()
|
||||
" It doesn't make sense to stage a hunk otherwise.
|
||||
silent write
|
||||
|
||||
if empty(gitgutter#hunk#current_hunk())
|
||||
call gitgutter#utility#warn('cursor is not in a hunk')
|
||||
else
|
||||
let diff_for_hunk = gitgutter#diff#generate_diff_for_hunk('revert')
|
||||
call gitgutter#utility#system(gitgutter#utility#command_in_directory_of_file('git apply --reverse --unidiff-zero - '), diff_for_hunk)
|
||||
|
||||
" reload file
|
||||
silent edit
|
||||
endif
|
||||
|
||||
silent! call repeat#set("\<Plug>GitGutterRevertHunk", -1)<CR>
|
||||
endif
|
||||
@@ -186,6 +194,9 @@ function! gitgutter#preview_hunk()
|
||||
if gitgutter#utility#is_active()
|
||||
silent write
|
||||
|
||||
if empty(gitgutter#hunk#current_hunk())
|
||||
call gitgutter#utility#warn('cursor is not in a hunk')
|
||||
else
|
||||
let diff_for_hunk = gitgutter#diff#generate_diff_for_hunk('preview')
|
||||
|
||||
silent! wincmd P
|
||||
@@ -200,6 +211,7 @@ function! gitgutter#preview_hunk()
|
||||
|
||||
wincmd p
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" }}}
|
||||
|
||||
@@ -63,8 +63,8 @@ function! gitgutter#hunk#prev_hunk(count)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Returns the hunk the cursor is currently in or 0 if the cursor isn't in a
|
||||
" hunk.
|
||||
" Returns the hunk the cursor is currently in or an empty list if the cursor
|
||||
" isn't in a hunk.
|
||||
function! gitgutter#hunk#current_hunk()
|
||||
let current_hunk = []
|
||||
|
||||
@@ -75,9 +75,7 @@ function! gitgutter#hunk#current_hunk()
|
||||
endif
|
||||
endfor
|
||||
|
||||
if len(current_hunk) == 4
|
||||
return current_hunk
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! gitgutter#hunk#cursor_in_hunk(hunk)
|
||||
|
||||
Reference in New Issue
Block a user