Skip to content

Commit

Permalink
Use filename in clean_smudge_filter_applies() function
Browse files Browse the repository at this point in the history
And move function to utility.

Since we change directory to the file's directory we can just use its
name rather than it path from the repo root.
  • Loading branch information
airblade committed Jun 3, 2023
1 parent cefbe30 commit f7f1286
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
16 changes: 1 addition & 15 deletions autoload/gitgutter/hunk.vim
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ endfunction
function! s:stage(hunk_diff)
let bufnr = bufnr('')

if s:clean_smudge_filter_applies(bufnr)
if gitgutter#utility#clean_smudge_filter_applies(bufnr)
let choice = input('File uses clean/smudge filter. Stage entire file (y/n)? ')
normal! :<ESC>
if choice =~ 'y'
Expand Down Expand Up @@ -654,17 +654,3 @@ function gitgutter#hunk#is_preview_window_open()
endif
return 0
endfunction


function! s:clean_smudge_filter_applies(bufnr)
let filtered = gitgutter#utility#getbufvar(a:bufnr, 'filter', -1)
if filtered == -1
let path = gitgutter#utility#repo_path(a:bufnr, 1)
let out = gitgutter#utility#system(
\ gitgutter#utility#cd_cmd(a:bufnr, g:gitgutter_git_executable.' '.g:gitgutter_git_args.' check-attr filter -- '.path)
\ )
let filtered = out !~ 'unspecified'
call gitgutter#utility#setbufvar(a:bufnr, 'filter', filtered)
endif
return filtered
endfunction
15 changes: 15 additions & 0 deletions autoload/gitgutter/utility.vim
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,21 @@ function! gitgutter#utility#set_repo_path(bufnr, continuation) abort
endfunction


function! gitgutter#utility#clean_smudge_filter_applies(bufnr)
let filtered = gitgutter#utility#getbufvar(a:bufnr, 'filter', -1)
if filtered == -1
let cmd = gitgutter#utility#cd_cmd(a:bufnr,
\ g:gitgutter_git_executable.' '.g:gitgutter_git_args.
\ ' check-attr filter -- '.
\ gitgutter#utility#shellescape(gitgutter#utility#filename(a:bufnr)))
let out = gitgutter#utility#system(cmd)
let filtered = out !~ 'unspecified'
call gitgutter#utility#setbufvar(a:bufnr, 'filter', filtered)
endif
return filtered
endfunction


function! gitgutter#utility#cd_cmd(bufnr, cmd) abort
let cd = s:unc_path(a:bufnr) ? 'pushd' : (gitgutter#utility#windows() && s:dos_shell() ? 'cd /d' : 'cd')
return cd.' '.s:dir(a:bufnr).' && '.a:cmd
Expand Down

0 comments on commit f7f1286

Please sign in to comment.