mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-08 11:33:48 -05:00
Add :GitGutterQuickFix command.
It loads all hunks into the quickfix list. Closes #617.
This commit is contained in:
@@ -16,6 +16,7 @@ Features:
|
|||||||
* Provides a hunk text object.
|
* Provides a hunk text object.
|
||||||
* Diffs against index (default) or any commit.
|
* Diffs against index (default) or any commit.
|
||||||
* Allows folding all unchanged text.
|
* Allows folding all unchanged text.
|
||||||
|
* Can load all hunk locations into quickfix list.
|
||||||
* Handles line endings correctly, even with repos that do CRLF conversion.
|
* Handles line endings correctly, even with repos that do CRLF conversion.
|
||||||
* Optional line highlighting.
|
* Optional line highlighting.
|
||||||
* Optional line number highlighting. (Only available in Neovim 0.3.2 or higher)
|
* Optional line number highlighting. (Only available in Neovim 0.3.2 or higher)
|
||||||
@@ -183,6 +184,8 @@ nmap ]h <Plug>GitGutterNextHunk
|
|||||||
nmap [h <Plug>GitGutterPrevHunk
|
nmap [h <Plug>GitGutterPrevHunk
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can load all your hunks into the quickfix list with `:GitGutterQuickFix`. Note this ignores any unsaved changes in your buffers.
|
||||||
|
|
||||||
You can stage or undo an individual hunk when your cursor is in it:
|
You can stage or undo an individual hunk when your cursor is in it:
|
||||||
|
|
||||||
* stage the hunk with `<Leader>hs` or
|
* stage the hunk with `<Leader>hs` or
|
||||||
|
|||||||
@@ -179,3 +179,29 @@ function! s:clear(bufnr)
|
|||||||
call s:reset_tick(a:bufnr)
|
call s:reset_tick(a:bufnr)
|
||||||
call gitgutter#utility#setbufvar(a:bufnr, 'path', '')
|
call gitgutter#utility#setbufvar(a:bufnr, 'path', '')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
" Note:
|
||||||
|
" - this runs synchronously
|
||||||
|
" - it ignores unsaved changes in buffers
|
||||||
|
" - it does not change to the repo root
|
||||||
|
function! gitgutter#quickfix()
|
||||||
|
let locations = []
|
||||||
|
let cmd = g:gitgutter_git_executable.' '.g:gitgutter_git_args.' --no-pager '.g:gitgutter_git_args.
|
||||||
|
\ ' diff --no-ext-diff --no-color -U0 '.g:gitgutter_diff_args
|
||||||
|
let diff = systemlist(cmd)
|
||||||
|
let lnum = 0
|
||||||
|
for line in diff
|
||||||
|
if line =~ '^diff --git [^"]'
|
||||||
|
let fname = matchlist(line, '^diff --git [abciow12]/\(\S\+\) ')[1]
|
||||||
|
elseif line =~ '^diff --git "'
|
||||||
|
let fname = matchlist(line, '^diff --git "[abciow12]/\(.\+\)" ')[1]
|
||||||
|
elseif line =~ '^@@'
|
||||||
|
let lnum = matchlist(line, '+\(\d\+\)')[1]
|
||||||
|
elseif lnum > 0
|
||||||
|
call add(locations, {'filename': fname, 'lnum': lnum, 'text': line})
|
||||||
|
let lnum = 0
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
call setqflist(locations)
|
||||||
|
endfunction
|
||||||
|
|||||||
@@ -160,6 +160,10 @@ Commands for jumping between hunks:~
|
|||||||
*gitgutter-:GitGutterPrevHunk*
|
*gitgutter-:GitGutterPrevHunk*
|
||||||
:GitGutterPrevHunk Jump to the previous [count] hunk.
|
:GitGutterPrevHunk Jump to the previous [count] hunk.
|
||||||
|
|
||||||
|
*gitgutter-:GitGutterQuickFix*
|
||||||
|
:GitGutterQuickFix Load all hunks into the |quickfix| list. Note this
|
||||||
|
ignores any unsaved changes in your buffers.
|
||||||
|
|
||||||
|
|
||||||
Commands for operating on a hunk:~
|
Commands for operating on a hunk:~
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,8 @@ command! -bar GitGutterBufferDisable call gitgutter#buffer_disable()
|
|||||||
command! -bar GitGutterBufferEnable call gitgutter#buffer_enable()
|
command! -bar GitGutterBufferEnable call gitgutter#buffer_enable()
|
||||||
command! -bar GitGutterBufferToggle call gitgutter#buffer_toggle()
|
command! -bar GitGutterBufferToggle call gitgutter#buffer_toggle()
|
||||||
|
|
||||||
|
command! -bar GitGutterQuickFix call gitgutter#quickfix()
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
|
|
||||||
" Line highlights {{{
|
" Line highlights {{{
|
||||||
|
|||||||
@@ -894,3 +894,19 @@ function Test_empty_file()
|
|||||||
|
|
||||||
set eol fixeol
|
set eol fixeol
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
function Test_quickfix()
|
||||||
|
call setline(5, ['A', 'B'])
|
||||||
|
call setline(9, ['C', 'D'])
|
||||||
|
write
|
||||||
|
|
||||||
|
GitGutterQuickFix
|
||||||
|
|
||||||
|
let expected = [
|
||||||
|
\ {'lnum': 5, 'bufnr': bufnr(''), 'text': '-e'},
|
||||||
|
\ {'lnum': 9, 'bufnr': bufnr(''), 'text': '-i'}
|
||||||
|
\ ]
|
||||||
|
|
||||||
|
call s:assert_list_of_dicts(expected, getqflist())
|
||||||
|
endfunction
|
||||||
|
|||||||
Reference in New Issue
Block a user