Skip to content

Commit

Permalink
Fix parsing of 'git ls-files -v' for filenames with spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
airblade committed Apr 25, 2022
1 parent 2f35907 commit 5dd8ab6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions autoload/gitgutter/utility.vim
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ endfunction
let s:set_path_handler = {}

function! s:set_path_handler.out(buffer, listing) abort
let [status, path] = split(s:strip_trailing_new_line(a:listing))
let listing = s:strip_trailing_new_line(a:listing)
let [status, path] = [listing[0], listing[2:]]
if status =~ '[[:lower:]]'
call gitgutter#utility#setbufvar(a:buffer, 'path', -3)
else
Expand Down Expand Up @@ -167,7 +168,8 @@ function! gitgutter#utility#set_repo_path(bufnr, continuation) abort
return
endif

let [status, path] = split(s:strip_trailing_new_line(listing))
let listing = s:strip_trailing_new_line(listing)
let [status, path] = [listing[0], listing[2:]]
if status =~ '[[:lower:]]'
call gitgutter#utility#setbufvar(a:bufnr, 'path', -3)
else
Expand Down
14 changes: 14 additions & 0 deletions test/test_gitgutter.vim
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,20 @@ function Test_filename_with_square_brackets()
endfunction


function Test_filename_with_space()
call system('touch fix\ ture.txt && git add fix\ ture.txt')
edit fix\ ture.txt
normal ggo*
call s:trigger_gitgutter()

let expected = [
\ {'lnum': 1, 'name': 'GitGutterLineAdded'},
\ {'lnum': 2, 'name': 'GitGutterLineAdded'}
\ ]
call s:assert_signs(expected, 'fix\ ture.txt')
endfunction


function Test_filename_leading_dash()
call system('touch -- -fixture.txt && git add -- -fixture.txt')
edit -fixture.txt
Expand Down

0 comments on commit 5dd8ab6

Please sign in to comment.