Support diffs relative to the working tree.

Closes #558.
This commit is contained in:
Andy Stewart
2019-08-28 09:22:06 +01:00
parent 83eb5377be
commit 8bafd08ef4
5 changed files with 29 additions and 2 deletions

View File

@@ -260,6 +260,7 @@ You can customise:
* How to handle non-gitgutter signs
* The signs' colours and symbols
* Line highlights
* Whether the diff is relative to the index (default) or working tree.
* The base of the diff
* Extra arguments for `git` when running `git diff`
* Extra arguments for `git diff`
@@ -383,6 +384,15 @@ highlight link GitGutterChangeLineNr Underlined
```
#### Whether the diff is relative to the index or working tree
By default diffs are relative to the index. How you can make them relative to the working tree:
```viml
let g:gitgutter_diff_relative_to = 'working_tree'
```
#### The base of the diff
By default buffers are diffed against the index. However you can diff against any commit by setting:
@@ -391,6 +401,8 @@ By default buffers are diffed against the index. However you can diff against a
let g:gitgutter_diff_base = '<commit SHA>'
```
This setting is ignored when the diffs are relative to the working tree.
#### Extra arguments for `git` when running `git diff`

View File

@@ -39,7 +39,7 @@ function! gitgutter#process_buffer(bufnr, force) abort
let diff = ''
try
let diff = gitgutter#diff#run_diff(a:bufnr, 'index', 0)
let diff = gitgutter#diff#run_diff(a:bufnr, g:gitgutter_diff_relative_to, 0)
catch /gitgutter not tracked/
call gitgutter#debug#log('Not tracked: '.gitgutter#utility#file(a:bufnr))
catch /gitgutter diff failed/

View File

@@ -227,7 +227,7 @@ function! s:hunk_op(op, ...)
if gitgutter#utility#is_active(bufnr)
" Get a (synchronous) diff.
let [async, g:gitgutter_async] = [g:gitgutter_async, 0]
let diff = gitgutter#diff#run_diff(bufnr, 'index', 1)
let diff = gitgutter#diff#run_diff(bufnr, g:gitgutter_diff_relative_to, 1)
let g:gitgutter_async = async
call gitgutter#hunk#set_hunks(bufnr, gitgutter#diff#parse_diff(diff))

View File

@@ -276,6 +276,7 @@ Git:~
|g:gitgutter_git_executable|
|g:gitgutter_git_args|
|g:gitgutter_diff_args|
|g:gitgutter_diff_relative_to|
|g:gitgutter_diff_base|
Grep:~
@@ -339,6 +340,15 @@ Use this option to pass any extra arguments to git-diff. For example:
let g:gitgutter_diff_args = '-w'
<
*g:gitgutter_diff_relative_to*
Default: empty
By default buffers are diffed against the index. Use this option to diff against
the working tree. For example:
>
let g:gitgutter_diff_relative_to = 'working_tree'
<
*g:gitgutter_diff_base*
Default: empty
@@ -348,6 +358,10 @@ a revision instead. For example:
let g:gitgutter_diff_base = '<some commit SHA>'
<
This setting is ignore when the diff is relative to the working tree
(|g:gitgutter_diff_relative_to|).
*g:gitgutter_grep*
*g:gitgutter_grep*
Default: 'grep'

View File

@@ -54,6 +54,7 @@ endif
call s:set('g:gitgutter_sign_removed_above_and_below', '[')
call s:set('g:gitgutter_sign_modified_removed', '~_')
call s:set('g:gitgutter_git_args', '')
call s:set('g:gitgutter_diff_relative_to', 'index')
call s:set('g:gitgutter_diff_args', '')
call s:set('g:gitgutter_diff_base', '')
call s:set('g:gitgutter_map_keys', 1)