mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-10 20:43:47 -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.
|
" It doesn't make sense to stage a hunk otherwise.
|
||||||
silent write
|
silent write
|
||||||
|
|
||||||
let diff_for_hunk = gitgutter#diff#generate_diff_for_hunk('stage')
|
if empty(gitgutter#hunk#current_hunk())
|
||||||
call gitgutter#utility#system(gitgutter#utility#command_in_directory_of_file('git apply --cached --unidiff-zero - '), diff_for_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
|
" refresh gitgutter's view of buffer
|
||||||
silent execute "GitGutter"
|
silent execute "GitGutter"
|
||||||
|
endif
|
||||||
|
|
||||||
silent! call repeat#set("\<Plug>GitGutterStageHunk", -1)<CR>
|
silent! call repeat#set("\<Plug>GitGutterStageHunk", -1)<CR>
|
||||||
endif
|
endif
|
||||||
@@ -172,11 +176,15 @@ function! gitgutter#revert_hunk()
|
|||||||
" It doesn't make sense to stage a hunk otherwise.
|
" It doesn't make sense to stage a hunk otherwise.
|
||||||
silent write
|
silent write
|
||||||
|
|
||||||
let diff_for_hunk = gitgutter#diff#generate_diff_for_hunk('revert')
|
if empty(gitgutter#hunk#current_hunk())
|
||||||
call gitgutter#utility#system(gitgutter#utility#command_in_directory_of_file('git apply --reverse --unidiff-zero - '), diff_for_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
|
" reload file
|
||||||
silent edit
|
silent edit
|
||||||
|
endif
|
||||||
|
|
||||||
silent! call repeat#set("\<Plug>GitGutterRevertHunk", -1)<CR>
|
silent! call repeat#set("\<Plug>GitGutterRevertHunk", -1)<CR>
|
||||||
endif
|
endif
|
||||||
@@ -186,19 +194,23 @@ function! gitgutter#preview_hunk()
|
|||||||
if gitgutter#utility#is_active()
|
if gitgutter#utility#is_active()
|
||||||
silent write
|
silent write
|
||||||
|
|
||||||
let diff_for_hunk = gitgutter#diff#generate_diff_for_hunk('preview')
|
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
|
silent! wincmd P
|
||||||
if !&previewwindow
|
if !&previewwindow
|
||||||
execute 'bo ' . &previewheight . ' new'
|
execute 'bo ' . &previewheight . ' new'
|
||||||
set previewwindow
|
set previewwindow
|
||||||
|
endif
|
||||||
|
|
||||||
|
setlocal noro modifiable filetype=diff buftype=nofile bufhidden=delete noswapfile
|
||||||
|
execute "%delete_"
|
||||||
|
call append(0, split(diff_for_hunk, "\n"))
|
||||||
|
|
||||||
|
wincmd p
|
||||||
endif
|
endif
|
||||||
|
|
||||||
setlocal noro modifiable filetype=diff buftype=nofile bufhidden=delete noswapfile
|
|
||||||
execute "%delete_"
|
|
||||||
call append(0, split(diff_for_hunk, "\n"))
|
|
||||||
|
|
||||||
wincmd p
|
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ function! gitgutter#hunk#prev_hunk(count)
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Returns the hunk the cursor is currently in or 0 if the cursor isn't in a
|
" Returns the hunk the cursor is currently in or an empty list if the cursor
|
||||||
" hunk.
|
" isn't in a hunk.
|
||||||
function! gitgutter#hunk#current_hunk()
|
function! gitgutter#hunk#current_hunk()
|
||||||
let current_hunk = []
|
let current_hunk = []
|
||||||
|
|
||||||
@@ -75,9 +75,7 @@ function! gitgutter#hunk#current_hunk()
|
|||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
if len(current_hunk) == 4
|
return current_hunk
|
||||||
return current_hunk
|
|
||||||
endif
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! gitgutter#hunk#cursor_in_hunk(hunk)
|
function! gitgutter#hunk#cursor_in_hunk(hunk)
|
||||||
|
|||||||
Reference in New Issue
Block a user