diff --git a/README.mkd b/README.mkd index d55432f..476054e 100644 --- a/README.mkd +++ b/README.mkd @@ -1,6 +1,6 @@ ## vim-gitgutter -A Vim plugin which shows a git diff in the 'gutter' (sign column). It shows whether each line has been added, modified, and where lines have been removed. You can also stage and revert individual hunks. +A Vim plugin which shows a git diff in the 'gutter' (sign column). It shows whether each line has been added, modified, and where lines have been removed. You can also stage and undo individual hunks. Features: @@ -8,7 +8,7 @@ Features: * Neovim: runs the diffs asynchronously. * Ensures signs are always as up to date as possible (but without running more than necessary). * Quick jumping between blocks of changed lines ("hunks"). -* Stage/revert/preview individual hunks. +* Stage/undo/preview individual hunks. * Diffs against index (default) or any commit. * Handles line endings correctly, even with repos that do CRLF conversion. * Optional line highlighting. @@ -61,7 +61,7 @@ If you are on Windows you may find the command prompt pops up briefly every time When you make a change to a file tracked by git, the diff markers should appear automatically. The delay is governed by vim's `updatetime` option; the default value is 4 seconds but I suggest reducing it to around 250ms (add `set updatetime=250` to your vimrc). -You can jump between hunks with `[c` and `]c`. You can preview, stage, and revert hunks with `hp`, `hs`, and `hr` respectively. +You can jump between hunks with `[c` and `]c`. You can preview, stage, and undo hunks with `hp`, `hs`, and `hu` respectively. You cannot currently unstage a staged hunk. @@ -112,20 +112,20 @@ nmap ]h GitGutterNextHunk nmap [h GitGutterPrevHunk ``` -You can stage or revert an individual hunk when your cursor is in it: +You can stage or undo an individual hunk when your cursor is in it: * stage the hunk with `hs` or -* revert it with `hr`. +* undo it with `hu`. See the FAQ if you want to unstage staged changes. The `.` command will work with both these if you install [repeat.vim](https://github.com/tpope/vim-repeat). -To set your own mappings for these, for example if you prefer the mnemonics hunk-add and hunk-undo: +To set your own mappings for these, for example if you prefer the mnemonics hunk-add and hunk-revert: ```viml nmap ha GitGutterStageHunk -nmap hu GitGutterRevertHunk +nmap hr GitGutterUndoHunk ``` And you can preview a hunk's changes with `hp`. You can of course change this mapping, e.g: @@ -273,7 +273,7 @@ To disable all key mappings: let g:gitgutter_map_keys = 0 ``` -See above for configuring maps for hunk-jumping and staging/reverting. +See above for configuring maps for hunk-jumping and staging/undoing. #### Use a custom `grep` command diff --git a/autoload/gitgutter.vim b/autoload/gitgutter.vim index 3053666..82d8b67 100644 --- a/autoload/gitgutter.vim +++ b/autoload/gitgutter.vim @@ -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("\GitGutterRevertHunk", -1) + silent! call repeat#set("\GitGutterUndoHunk", -1) endif endfunction diff --git a/autoload/gitgutter/diff.vim b/autoload/gitgutter/diff.vim index 3b18777..c5b875c 100644 --- a/autoload/gitgutter/diff.vim +++ b/autoload/gitgutter/diff.vim @@ -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) diff --git a/doc/gitgutter.txt b/doc/gitgutter.txt index d36651f..739f7db 100644 --- a/doc/gitgutter.txt +++ b/doc/gitgutter.txt @@ -98,13 +98,13 @@ Commands for jumping between marked hunks: :GitGutterPrevHunk *:GitGutterPrevHunk* Jump to the previous marked hunk. Takes a count. -Commands for staging or reverting individual hunks: +Commands for staging or undoing individual hunks: :GitGutterStageHunk *:GitGutterStageHunk* Stage the hunk the cursor is in. - :GitGutterRevertHunk *:GitGutterRevertHunk* - Revert the hunk the cursor is in. + :GitGutterUndoHunk *:GitGutterUndoHunk* + Undo the hunk the cursor is in. :GitGutterPreviewHunk *:GitGutterPreviewHunk* Preview the hunk the cursor is in. @@ -215,10 +215,10 @@ To change the hunk-jumping maps (defaults shown): nmap ]c GitGutterNextHunk < -To change the hunk-staging/reverting/previewing maps (defaults shown): +To change the hunk-staging/undoing/previewing maps (defaults shown): > nmap hs GitGutterStageHunk - nmap hr GitGutterRevertHunk + nmap hu GitGutterUndoHunk nmap hp GitGutterPreviewHunk < diff --git a/plugin/gitgutter.vim b/plugin/gitgutter.vim index 2597f81..5ff57fb 100644 --- a/plugin/gitgutter.vim +++ b/plugin/gitgutter.vim @@ -90,7 +90,8 @@ command -bar -count=1 GitGutterNextHunk call gitgutter#hunk#next_hunk() command -bar -count=1 GitGutterPrevHunk call gitgutter#hunk#prev_hunk() command -bar GitGutterStageHunk call gitgutter#stage_hunk() -command -bar GitGutterRevertHunk call gitgutter#revert_hunk() +command -bar GitGutterUndoHunk call gitgutter#undo_hunk() +command -bar GitGutterRevertHunk echomsg 'GitGutterRevertHunk is deprecated. Use GitGutterUndoHunk'call gitgutter#undo_hunk() command -bar GitGutterPreviewHunk call gitgutter#preview_hunk() " Returns the git-diff hunks for the file or an empty list if there @@ -141,15 +142,16 @@ endif nnoremap GitGutterStageHunk :GitGutterStageHunk -nnoremap GitGutterRevertHunk :GitGutterRevertHunk +nnoremap GitGutterUndoHunk :GitGutterUndoHunk nnoremap GitGutterPreviewHunk :GitGutterPreviewHunk if g:gitgutter_map_keys if !hasmapto('GitGutterStageHunk') && maparg('hs', 'n') ==# '' nmap hs GitGutterStageHunk endif - if !hasmapto('GitGutterRevertHunk') && maparg('hr', 'n') ==# '' - nmap hr GitGutterRevertHunk + if !hasmapto('GitGutterUndoHunk') && maparg('hu', 'n') ==# '' + nmap hu GitGutterUndoHunk + nmap hr GitGutterUndoHunk:echomsg 'hr is deprecated. Use hu' endif if !hasmapto('GitGutterPreviewHunk') && maparg('hp', 'n') ==# '' nmap hp GitGutterPreviewHunk diff --git a/test/hunkHunkOutsideNoopRevertGitDiffStaged.expected b/test/hunkHunkOutsideNoopUndoGitDiffStaged.expected similarity index 100% rename from test/hunkHunkOutsideNoopRevertGitDiffStaged.expected rename to test/hunkHunkOutsideNoopUndoGitDiffStaged.expected diff --git a/test/hunkOutsideNoopRevertSigns.expected b/test/hunkOutsideNoopUndoSigns.expected similarity index 100% rename from test/hunkOutsideNoopRevertSigns.expected rename to test/hunkOutsideNoopUndoSigns.expected diff --git a/test/hunkRevertGitDiff.expected b/test/hunkUndoGitDiff.expected similarity index 100% rename from test/hunkRevertGitDiff.expected rename to test/hunkUndoGitDiff.expected diff --git a/test/hunkRevertNearbyGitDiff.expected b/test/hunkUndoNearbyGitDiff.expected similarity index 100% rename from test/hunkRevertNearbyGitDiff.expected rename to test/hunkUndoNearbyGitDiff.expected diff --git a/test/hunkRevertNearbySigns.expected b/test/hunkUndoNearbySigns.expected similarity index 100% rename from test/hunkRevertNearbySigns.expected rename to test/hunkUndoNearbySigns.expected diff --git a/test/hunkRevertSigns.expected b/test/hunkUndoSigns.expected similarity index 100% rename from test/hunkRevertSigns.expected rename to test/hunkUndoSigns.expected diff --git a/test/testHunkOutsideNoop.vim b/test/testHunkOutsideNoop.vim index 3feba9c..6601e6d 100644 --- a/test/testHunkOutsideNoop.vim +++ b/test/testHunkOutsideNoop.vim @@ -7,7 +7,7 @@ execute 'GitGutterStageHunk' call DumpSigns('hunkOutsideNoopStageSigns') call DumpGitDiffStaged('hunkHunkOutsideNoopStageGitDiffStaged') -execute 'GitGutterRevertHunk' -call DumpSigns('hunkOutsideNoopRevertSigns') -call DumpGitDiffStaged('hunkHunkOutsideNoopRevertGitDiffStaged') +execute 'GitGutterUndoHunk' +call DumpSigns('hunkOutsideNoopUndoSigns') +call DumpGitDiffStaged('hunkHunkOutsideNoopUndoGitDiffStaged') diff --git a/test/testHunkRevert.vim b/test/testHunkRevert.vim deleted file mode 100644 index 21ceeba..0000000 --- a/test/testHunkRevert.vim +++ /dev/null @@ -1,7 +0,0 @@ -source helper.vim -call Setup() - -normal 5Gi* -execute 'GitGutterRevertHunk' -call DumpSigns('hunkRevertSigns') -call DumpGitDiffStaged('hunkRevertGitDiff') diff --git a/test/testHunkRevertNearbyHunk.vim b/test/testHunkRevertNearbyHunk.vim deleted file mode 100644 index 0c5c508..0000000 --- a/test/testHunkRevertNearbyHunk.vim +++ /dev/null @@ -1,9 +0,0 @@ -source helper.vim -call Setup() - -execute "normal! 2Gox\y\z" -normal 2jdd -normal k -execute 'GitGutterRevertHunk' -call DumpSigns('hunkRevertNearbySigns') -call DumpGitDiff('hunkRevertNearbyGitDiff') diff --git a/test/testHunkUndo.vim b/test/testHunkUndo.vim new file mode 100644 index 0000000..9d187a7 --- /dev/null +++ b/test/testHunkUndo.vim @@ -0,0 +1,7 @@ +source helper.vim +call Setup() + +normal 5Gi* +execute 'GitGutterUndoHunk' +call DumpSigns('hunkUndoSigns') +call DumpGitDiffStaged('hunkUndoGitDiff') diff --git a/test/testHunkUndoNearbyHunk.vim b/test/testHunkUndoNearbyHunk.vim new file mode 100644 index 0000000..5721f2d --- /dev/null +++ b/test/testHunkUndoNearbyHunk.vim @@ -0,0 +1,9 @@ +source helper.vim +call Setup() + +execute "normal! 2Gox\y\z" +normal 2jdd +normal k +execute 'GitGutterUndoHunk' +call DumpSigns('hunkUndoNearbySigns') +call DumpGitDiff('hunkUndoNearbyGitDiff')