-
I have some pre-commit hooks set up for a project. When I need to act on the hook diagnostics from a commit, I dump the results to either the preview window (with Thanks for building such a great plugin! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
There's no built-in way to route Git output directly into the quickfix list. I've thought about adding it but it seems extremely unhelpful to do so with the default value of But in terms of solving your actual problem, you can do that much more elegantly by tapping into the function! s:AfterGit() abort
if !exists('*FugitiveResult')
return
endif
let result = FugitiveResult()
if !filereadable(get(result, 'file', '')) || get(result.args, 0, '') !=# 'commit' || !get(result, 'exit_status')
return
endif
let args = result.args[0 : index(result.args, '--')]
let root = FugitiveWorkTree(result) . '/'
let list = []
let valid = 0
for line in readfile(result.file)
let match = matchlist(line, '\v^([^:]*):(\d+): *(.*)')
if len(match) && filereadable(root . match[1])
let valid = 1
if index(args, '-a') >= 0 || index(args, '--all') >= 0
call add(list, {'filename': FugitiveFind(':(top)' . match[1], result), 'lnum': +match[2], 'text': match[3], 'valid': 1})
else
let module = ':0:' . match[1]
call add(list, {'filename': FugitiveFind(module, result), 'module': module, 'lnum': +match[2], 'text': match[3], 'valid': 1})
endif
else
call add(list, {'text': line})
endif
endfor
if valid
call setqflist(list)
let winnr = winnr()
silent botright copen
if winnr != winnr()
exe winnr . 'wincmd w'
endif
endif
endfunction
augroup gitprecommit
autocmd!
autocmd User FugitiveChanged call s:AfterGit()
augroup END This one goes to a great deal of trouble to try to account for if changes are in the index and work tree; if you're running a test suite you don't need to do that. Rough take on a function! s:AfterGit() abort
if !exists('*FugitiveResult')
return
endif
let result = FugitiveResult()
if !filereadable(get(result, 'file', '')) || get(result.args, 0, '') !=# 'commit' || !get(result, 'exit_status')
return
endif
exe 'cgetfile' fnameescape(result.file)
endfunction |
Beta Was this translation helpful? Give feedback.
There's no built-in way to route Git output directly into the quickfix list. I've thought about adding it but it seems extremely unhelpful to do so with the default value of
'errorformat'
. For the niches where it's helpful, your 2 step solution gets the job done.But in terms of solving your actual problem, you can do that much more elegantly by tapping into the
FugitiveChanged
event, which triggers on every:Git
call. Here's an example that operates on the whitespace error checking provided bypre-commit.sample
: