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:
Andy Stewart
2022-04-23 08:25:46 +01:00
parent d5bae10403
commit 626541edeb
5 changed files with 35 additions and 6 deletions

View File

@@ -77,6 +77,10 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
throw 'gitgutter not tracked'
endif
if gitgutter#utility#repo_path(a:bufnr, 0) == -3
throw 'gitgutter assume unchanged'
endif
" Wrap compound commands in parentheses to make Windows happy.
" bash doesn't mind the parentheses.
let cmd = '('

View File

@@ -108,6 +108,7 @@ endfunction
" * non-empty string - path
" * -1 - pending
" * -2 - not tracked by git
" * -3 - assume unchanged
function! gitgutter#utility#repo_path(bufnr, shellesc) abort
let p = gitgutter#utility#getbufvar(a:bufnr, 'path', '')
return a:shellesc ? gitgutter#utility#shellescape(p) : p
@@ -116,9 +117,13 @@ endfunction
let s:set_path_handler = {}
function! s:set_path_handler.out(buffer, path) abort
let path = s:strip_trailing_new_line(a:path)
call gitgutter#utility#setbufvar(a:buffer, 'path', path)
function! s:set_path_handler.out(buffer, listing) abort
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)
endif
if type(self.continuation) == type(function('tr'))
call self.continuation()
@@ -140,9 +145,10 @@ function! gitgutter#utility#set_repo_path(bufnr, continuation) abort
" * non-empty string - path
" * -1 - pending
" * -2 - not tracked by git
" * -3 - assume unchanged
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')
let handler = copy(s:set_path_handler)
@@ -151,11 +157,18 @@ function! gitgutter#utility#set_repo_path(bufnr, continuation) abort
return 'async'
endif
let path = gitgutter#utility#system(cmd)
let listing = gitgutter#utility#system(cmd)
if v:shell_error
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
call gitgutter#utility#setbufvar(a:bufnr, 'path', s:strip_trailing_new_line(path))
call gitgutter#utility#setbufvar(a:bufnr, 'path', path)
endif
endfunction