mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-09 12:03:48 -05:00
Heeds git's "assume unchanged" bit
I.e. does not diff files which should be assumed unchanged.
See:
git update-index --[no-]assume-unchanged -- <file>
git ls-files -v
Closes #826.
This commit is contained in:
@@ -18,6 +18,7 @@ Features:
|
|||||||
* Stage partial hunks.
|
* Stage partial hunks.
|
||||||
* Provides a hunk text object.
|
* Provides a hunk text object.
|
||||||
* Diffs against index (default) or any commit.
|
* Diffs against index (default) or any commit.
|
||||||
|
* Heeds git's "assume unchanged" bit.
|
||||||
* Allows folding all unchanged text.
|
* Allows folding all unchanged text.
|
||||||
* Provides fold text showing whether folded lines have been changed.
|
* Provides fold text showing whether folded lines have been changed.
|
||||||
* Can load all hunk locations into quickfix list or the current window's location list.
|
* Can load all hunk locations into quickfix list or the current window's location list.
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ function! gitgutter#process_buffer(bufnr, force) abort
|
|||||||
let diff = gitgutter#diff#run_diff(a:bufnr, g:gitgutter_diff_relative_to, 0)
|
let diff = gitgutter#diff#run_diff(a:bufnr, g:gitgutter_diff_relative_to, 0)
|
||||||
catch /gitgutter not tracked/
|
catch /gitgutter not tracked/
|
||||||
call gitgutter#debug#log('Not tracked: '.gitgutter#utility#file(a:bufnr))
|
call gitgutter#debug#log('Not tracked: '.gitgutter#utility#file(a:bufnr))
|
||||||
|
catch /gitgutter assume unchanged/
|
||||||
|
call gitgutter#debug#log('Assume unchanged: '.gitgutter#utility#file(a:bufnr))
|
||||||
catch /gitgutter diff failed/
|
catch /gitgutter diff failed/
|
||||||
call gitgutter#debug#log('Diff failed: '.gitgutter#utility#file(a:bufnr))
|
call gitgutter#debug#log('Diff failed: '.gitgutter#utility#file(a:bufnr))
|
||||||
call gitgutter#hunk#reset(a:bufnr)
|
call gitgutter#hunk#reset(a:bufnr)
|
||||||
|
|||||||
@@ -77,6 +77,10 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
|
|||||||
throw 'gitgutter not tracked'
|
throw 'gitgutter not tracked'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if gitgutter#utility#repo_path(a:bufnr, 0) == -3
|
||||||
|
throw 'gitgutter assume unchanged'
|
||||||
|
endif
|
||||||
|
|
||||||
" Wrap compound commands in parentheses to make Windows happy.
|
" Wrap compound commands in parentheses to make Windows happy.
|
||||||
" bash doesn't mind the parentheses.
|
" bash doesn't mind the parentheses.
|
||||||
let cmd = '('
|
let cmd = '('
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ endfunction
|
|||||||
" * non-empty string - path
|
" * non-empty string - path
|
||||||
" * -1 - pending
|
" * -1 - pending
|
||||||
" * -2 - not tracked by git
|
" * -2 - not tracked by git
|
||||||
|
" * -3 - assume unchanged
|
||||||
function! gitgutter#utility#repo_path(bufnr, shellesc) abort
|
function! gitgutter#utility#repo_path(bufnr, shellesc) abort
|
||||||
let p = gitgutter#utility#getbufvar(a:bufnr, 'path', '')
|
let p = gitgutter#utility#getbufvar(a:bufnr, 'path', '')
|
||||||
return a:shellesc ? gitgutter#utility#shellescape(p) : p
|
return a:shellesc ? gitgutter#utility#shellescape(p) : p
|
||||||
@@ -116,9 +117,13 @@ endfunction
|
|||||||
|
|
||||||
let s:set_path_handler = {}
|
let s:set_path_handler = {}
|
||||||
|
|
||||||
function! s:set_path_handler.out(buffer, path) abort
|
function! s:set_path_handler.out(buffer, listing) abort
|
||||||
let path = s:strip_trailing_new_line(a:path)
|
let [status, path] = split(s:strip_trailing_new_line(a:listing))
|
||||||
|
if status =~ '[[:lower:]]'
|
||||||
|
call gitgutter#utility#setbufvar(a:buffer, 'path', -3)
|
||||||
|
else
|
||||||
call gitgutter#utility#setbufvar(a:buffer, 'path', path)
|
call gitgutter#utility#setbufvar(a:buffer, 'path', path)
|
||||||
|
endif
|
||||||
|
|
||||||
if type(self.continuation) == type(function('tr'))
|
if type(self.continuation) == type(function('tr'))
|
||||||
call self.continuation()
|
call self.continuation()
|
||||||
@@ -140,9 +145,10 @@ function! gitgutter#utility#set_repo_path(bufnr, continuation) abort
|
|||||||
" * non-empty string - path
|
" * non-empty string - path
|
||||||
" * -1 - pending
|
" * -1 - pending
|
||||||
" * -2 - not tracked by git
|
" * -2 - not tracked by git
|
||||||
|
" * -3 - assume unchanged
|
||||||
|
|
||||||
call gitgutter#utility#setbufvar(a:bufnr, 'path', -1)
|
call gitgutter#utility#setbufvar(a:bufnr, 'path', -1)
|
||||||
let cmd = gitgutter#utility#cd_cmd(a:bufnr, g:gitgutter_git_executable.' '.g:gitgutter_git_args.' ls-files --error-unmatch --full-name -z -- '.gitgutter#utility#shellescape(s:filename(a:bufnr)))
|
let cmd = gitgutter#utility#cd_cmd(a:bufnr, g:gitgutter_git_executable.' '.g:gitgutter_git_args.' ls-files -v --error-unmatch --full-name -z -- '.gitgutter#utility#shellescape(s:filename(a:bufnr)))
|
||||||
|
|
||||||
if g:gitgutter_async && gitgutter#async#available() && !has('vim_starting')
|
if g:gitgutter_async && gitgutter#async#available() && !has('vim_starting')
|
||||||
let handler = copy(s:set_path_handler)
|
let handler = copy(s:set_path_handler)
|
||||||
@@ -151,11 +157,18 @@ function! gitgutter#utility#set_repo_path(bufnr, continuation) abort
|
|||||||
return 'async'
|
return 'async'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let path = gitgutter#utility#system(cmd)
|
let listing = gitgutter#utility#system(cmd)
|
||||||
|
|
||||||
if v:shell_error
|
if v:shell_error
|
||||||
call gitgutter#utility#setbufvar(a:bufnr, 'path', -2)
|
call gitgutter#utility#setbufvar(a:bufnr, 'path', -2)
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
let [status, path] = split(s:strip_trailing_new_line(listing))
|
||||||
|
if status =~ '[[:lower:]]'
|
||||||
|
call gitgutter#utility#setbufvar(a:bufnr, 'path', -3)
|
||||||
else
|
else
|
||||||
call gitgutter#utility#setbufvar(a:bufnr, 'path', s:strip_trailing_new_line(path))
|
call gitgutter#utility#setbufvar(a:bufnr, 'path', path)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
@@ -1126,3 +1126,12 @@ function Test_foldtext()
|
|||||||
call assert_equal(0, gitgutter#fold#is_changed())
|
call assert_equal(0, gitgutter#fold#is_changed())
|
||||||
call assert_equal('+- 3 lines: a', gitgutter#fold#foldtext())
|
call assert_equal('+- 3 lines: a', gitgutter#fold#foldtext())
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
function Test_assume_unchanged()
|
||||||
|
call system("git update-index --assume-unchanged fixture.txt")
|
||||||
|
unlet b:gitgutter.path " it was already set when fixture.txt was loaded in SetUp()
|
||||||
|
normal ggo*
|
||||||
|
call s:trigger_gitgutter()
|
||||||
|
call s:assert_signs([], 'fixture.txt')
|
||||||
|
endfunction
|
||||||
|
|||||||
Reference in New Issue
Block a user