Enable diffing against any commit.

Closes #309.
This commit is contained in:
Andy Stewart
2016-04-20 11:19:34 +01:00
parent 78d83c7056
commit 75eee3e407
4 changed files with 27 additions and 4 deletions

View File

@@ -9,6 +9,7 @@ Features:
* 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.
* Diffs against index (default) or any commit.
* Handles line endings correctly, even with repos that do CRLF conversion.
* Optional line highlighting.
* Fully customisable (signs, sign column, line highlights, mappings, extra git-diff arguments, etc).
@@ -178,6 +179,7 @@ You can customise:
* Whether or not the sign column is shown when there aren't any signs (defaults to no)
* The signs' colours and symbols
* Line highlights
* The base of the diff
* Extra arguments for `git diff`
* Key mappings
* Whether or not vim-gitgutter is on initially (defaults to on)
@@ -244,6 +246,16 @@ GitGutterDeleteLine " default: links to DiffDelete
GitGutterChangeDeleteLine " default: links to GitGutterChangeLineDefault, i.e. DiffChange
```
#### The base of the diff
By default buffers are diffed against the index. However you can diff against any commit by setting:
```viml
let g:gitgutter_diff_base = '<commit SHA>'
```
#### Extra arguments for `git diff`
If you want to pass extra arguments to `git diff`, for example to ignore whitespace, do so like this:

View File

@@ -63,7 +63,7 @@ function! gitgutter#diff#run_diff(realtime, preserve_full_diff)
endif
if a:realtime
let blob_name = ':'.gitgutter#utility#shellescape(gitgutter#utility#file_relative_to_repo_root())
let blob_name = g:gitgutter_diff_base.':'.gitgutter#utility#shellescape(gitgutter#utility#file_relative_to_repo_root())
let blob_file = s:temp_index
let buff_file = s:temp_buffer
let extension = gitgutter#utility#extension()
@@ -88,11 +88,12 @@ function! gitgutter#diff#run_diff(realtime, preserve_full_diff)
call setpos("']", op_mark_end)
endif
let cmd .= 'git -c "diff.autorefreshindex=0" diff --no-ext-diff --no-color -U0 '.g:gitgutter_diff_args.' -- '
let cmd .= 'git -c "diff.autorefreshindex=0" diff --no-ext-diff --no-color -U0 '.g:gitgutter_diff_args.' '
if a:realtime
let cmd .= blob_file.' '.buff_file
let cmd .= ' -- '.blob_file.' '.buff_file
else
let cmd .= gitgutter#utility#shellescape(gitgutter#utility#filename())
let cmd .= g:gitgutter_diff_base.' -- '.gitgutter#utility#shellescape(gitgutter#utility#filename())
endif
if !a:preserve_full_diff && s:grep_available

View File

@@ -117,6 +117,7 @@ You can customise:
- The sign column's colours
- The signs' colours and symbols
- Line highlights
- The base of the diff
- Extra arguments for git-diff
- Key mappings
- The grep executable used
@@ -185,6 +186,14 @@ colorscheme or |vimrc|:
GitGutterChangeDeleteLine " default: links to GitGutterChangeLineDefault
<
THE BASE OF THE DIFF
By default buffers are diffed against the index. To diff against a commit
instead:
>
let g:gitgutter_diff_base = '<commit SHA>'
<
EXTRA ARGUMENTS FOR GIT-DIFF
To pass extra arguments to git-diff, add this to your |vimrc|:

View File

@@ -46,6 +46,7 @@ endtry
call s:set('g:gitgutter_sign_modified_removed', '~_')
call s:set('g:gitgutter_diff_args', '')
call s:set('g:gitgutter_diff_base', '')
call s:set('g:gitgutter_map_keys', 1)
call s:set('g:gitgutter_avoid_cmd_prompt_on_windows', 1)