Skip to content

Commit 626541e

Browse files
committed
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 airblade#826.
1 parent d5bae10 commit 626541e

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

README.mkd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Features:
1818
* Stage partial hunks.
1919
* Provides a hunk text object.
2020
* Diffs against index (default) or any commit.
21+
* Heeds git's "assume unchanged" bit.
2122
* Allows folding all unchanged text.
2223
* Provides fold text showing whether folded lines have been changed.
2324
* Can load all hunk locations into quickfix list or the current window's location list.

autoload/gitgutter.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ function! gitgutter#process_buffer(bufnr, force) abort
4444
let diff = gitgutter#diff#run_diff(a:bufnr, g:gitgutter_diff_relative_to, 0)
4545
catch /gitgutter not tracked/
4646
call gitgutter#debug#log('Not tracked: '.gitgutter#utility#file(a:bufnr))
47+
catch /gitgutter assume unchanged/
48+
call gitgutter#debug#log('Assume unchanged: '.gitgutter#utility#file(a:bufnr))
4749
catch /gitgutter diff failed/
4850
call gitgutter#debug#log('Diff failed: '.gitgutter#utility#file(a:bufnr))
4951
call gitgutter#hunk#reset(a:bufnr)

autoload/gitgutter/diff.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
7777
throw 'gitgutter not tracked'
7878
endif
7979

80+
if gitgutter#utility#repo_path(a:bufnr, 0) == -3
81+
throw 'gitgutter assume unchanged'
82+
endif
83+
8084
" Wrap compound commands in parentheses to make Windows happy.
8185
" bash doesn't mind the parentheses.
8286
let cmd = '('

autoload/gitgutter/utility.vim

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ endfunction
108108
" * non-empty string - path
109109
" * -1 - pending
110110
" * -2 - not tracked by git
111+
" * -3 - assume unchanged
111112
function! gitgutter#utility#repo_path(bufnr, shellesc) abort
112113
let p = gitgutter#utility#getbufvar(a:bufnr, 'path', '')
113114
return a:shellesc ? gitgutter#utility#shellescape(p) : p
@@ -116,9 +117,13 @@ endfunction
116117

117118
let s:set_path_handler = {}
118119

119-
function! s:set_path_handler.out(buffer, path) abort
120-
let path = s:strip_trailing_new_line(a:path)
121-
call gitgutter#utility#setbufvar(a:buffer, 'path', path)
120+
function! s:set_path_handler.out(buffer, listing) abort
121+
let [status, path] = split(s:strip_trailing_new_line(a:listing))
122+
if status =~ '[[:lower:]]'
123+
call gitgutter#utility#setbufvar(a:buffer, 'path', -3)
124+
else
125+
call gitgutter#utility#setbufvar(a:buffer, 'path', path)
126+
endif
122127

123128
if type(self.continuation) == type(function('tr'))
124129
call self.continuation()
@@ -140,9 +145,10 @@ function! gitgutter#utility#set_repo_path(bufnr, continuation) abort
140145
" * non-empty string - path
141146
" * -1 - pending
142147
" * -2 - not tracked by git
148+
" * -3 - assume unchanged
143149

144150
call gitgutter#utility#setbufvar(a:bufnr, 'path', -1)
145-
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)))
151+
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)))
146152

147153
if g:gitgutter_async && gitgutter#async#available() && !has('vim_starting')
148154
let handler = copy(s:set_path_handler)
@@ -151,11 +157,18 @@ function! gitgutter#utility#set_repo_path(bufnr, continuation) abort
151157
return 'async'
152158
endif
153159

154-
let path = gitgutter#utility#system(cmd)
160+
let listing = gitgutter#utility#system(cmd)
161+
155162
if v:shell_error
156163
call gitgutter#utility#setbufvar(a:bufnr, 'path', -2)
164+
return
165+
endif
166+
167+
let [status, path] = split(s:strip_trailing_new_line(listing))
168+
if status =~ '[[:lower:]]'
169+
call gitgutter#utility#setbufvar(a:bufnr, 'path', -3)
157170
else
158-
call gitgutter#utility#setbufvar(a:bufnr, 'path', s:strip_trailing_new_line(path))
171+
call gitgutter#utility#setbufvar(a:bufnr, 'path', path)
159172
endif
160173
endfunction
161174

test/test_gitgutter.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,3 +1126,12 @@ function Test_foldtext()
11261126
call assert_equal(0, gitgutter#fold#is_changed())
11271127
call assert_equal('+- 3 lines: a', gitgutter#fold#foldtext())
11281128
endfunction
1129+
1130+
1131+
function Test_assume_unchanged()
1132+
call system("git update-index --assume-unchanged fixture.txt")
1133+
unlet b:gitgutter.path " it was already set when fixture.txt was loaded in SetUp()
1134+
normal ggo*
1135+
call s:trigger_gitgutter()
1136+
call s:assert_signs([], 'fixture.txt')
1137+
endfunction

0 commit comments

Comments
 (0)