mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-10 04:23:46 -05:00
Use "undo" instead of "revert" for discarding a hunk.
"Undo" is a better name than "revert" because: - "revert" sounds like it has something to do with `git-revert` but they are entirely different; - "undo" is consistent with vim's "undo": discarding changes and going back to the original. Maintain backwards compatibility and add deprecation warnings. Closes #306.
This commit is contained in:
@@ -201,7 +201,7 @@ function! gitgutter#stage_hunk()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! gitgutter#revert_hunk()
|
||||
function! gitgutter#undo_hunk()
|
||||
if gitgutter#utility#is_active()
|
||||
" Ensure the working copy of the file is up to date.
|
||||
" It doesn't make sense to stage a hunk otherwise.
|
||||
@@ -212,14 +212,14 @@ function! gitgutter#revert_hunk()
|
||||
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(diff, 'revert')
|
||||
let diff_for_hunk = gitgutter#diff#generate_diff_for_hunk(diff, 'undo')
|
||||
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>
|
||||
silent! call repeat#set("\<Plug>GitGutterUndoHunk", -1)<CR>
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -291,11 +291,11 @@ endfunction
|
||||
" Generates a zero-context diff for the current hunk.
|
||||
"
|
||||
" diff - the full diff for the buffer
|
||||
" type - stage | revert | preview
|
||||
" type - stage | undo | preview
|
||||
function! gitgutter#diff#generate_diff_for_hunk(diff, type)
|
||||
let diff_for_hunk = gitgutter#diff#discard_hunks(a:diff, a:type == 'stage' || a:type == 'revert')
|
||||
let diff_for_hunk = gitgutter#diff#discard_hunks(a:diff, a:type == 'stage' || a:type == 'undo')
|
||||
|
||||
if a:type == 'stage' || a:type == 'revert'
|
||||
if a:type == 'stage' || a:type == 'undo'
|
||||
let diff_for_hunk = gitgutter#diff#adjust_hunk_summary(diff_for_hunk, a:type == 'stage')
|
||||
endif
|
||||
|
||||
@@ -330,7 +330,7 @@ endfunction
|
||||
" Adjust hunk summary (from's / to's line number) to ignore changes above/before this one.
|
||||
"
|
||||
" diff_for_hunk - a diff containing only the hunk of interest
|
||||
" staging - truthy if the hunk is to be staged, falsy if it is to be reverted
|
||||
" staging - truthy if the hunk is to be staged, falsy if it is to be undone
|
||||
"
|
||||
" TODO: push this down to #discard_hunks?
|
||||
function! gitgutter#diff#adjust_hunk_summary(diff_for_hunk, staging)
|
||||
|
||||
Reference in New Issue
Block a user