diff --git a/autoload/gitgutter/utility.vim b/autoload/gitgutter/utility.vim index 277be94..c58afe0 100644 --- a/autoload/gitgutter/utility.vim +++ b/autoload/gitgutter/utility.vim @@ -115,7 +115,7 @@ function! gitgutter#utility#set_repo_path(bufnr) abort " * -2 - not tracked by git call gitgutter#utility#setbufvar(a:bufnr, 'path', -1) - let cmd = gitgutter#utility#cd_cmd(a:bufnr, g:gitgutter_git_executable.' ls-files --error-unmatch --full-name -- '.gitgutter#utility#shellescape(s:filename(a:bufnr))) + let cmd = gitgutter#utility#cd_cmd(a:bufnr, g:gitgutter_git_executable.' ls-files --error-unmatch --full-name -z -- '.gitgutter#utility#shellescape(s:filename(a:bufnr))) if g:gitgutter_async && gitgutter#async#available() if has('lambda') @@ -202,8 +202,13 @@ function! s:exists_file(bufnr) abort return filereadable(s:abs_path(a:bufnr, 0)) endfunction +" Get rid of any trailing new line or SOH character. +" +" git ls-files -z produces output with null line termination. +" Vim's system() replaces any null characters in the output +" with SOH (start of header), i.e. ^A. function! s:strip_trailing_new_line(line) abort - return substitute(a:line, '\n$', '', '') + return substitute(a:line, '[[:cntrl:]]$', '', '') endfunction function! gitgutter#utility#windows() diff --git a/test/test_gitgutter.vim b/test/test_gitgutter.vim index 1e13cc6..4781e82 100644 --- a/test/test_gitgutter.vim +++ b/test/test_gitgutter.vim @@ -191,6 +191,20 @@ function Test_filename_leading_dash() endfunction +function Test_filename_umlaut() + call system('touch -- fixtüre.txt && git add -- fixtüre.txt') + edit fixtüre.txt + normal ggo* + call s:trigger_gitgutter() + + let expected = [ + \ 'line=1 id=3000 name=GitGutterLineAdded', + \ 'line=2 id=3001 name=GitGutterLineAdded' + \ ] + call assert_equal(expected, s:signs('fixtüre.txt')) +endfunction + + " FIXME: this test fails when it is the first (or only) test to be run function Test_follow_symlink() let tmp = 'symlink'