From 84bc2d68c0b32440bd1b12f245607a563a9421e4 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Wed, 3 Jan 2024 16:06:27 +0000 Subject: [PATCH] Fix base_path() to handle filenames with colons This bug was introduced when teaching gitgutter to handle file moves in #872. Fixes #877. --- autoload/gitgutter/utility.vim | 3 ++- test/test_gitgutter.vim | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/autoload/gitgutter/utility.vim b/autoload/gitgutter/utility.vim index ec2696e..162f547 100644 --- a/autoload/gitgutter/utility.vim +++ b/autoload/gitgutter/utility.vim @@ -252,7 +252,8 @@ function! gitgutter#utility#base_path(bufnr) " If we already know the original path at this diff base, return it. let basepath = gitgutter#utility#getbufvar(a:bufnr, 'basepath', '') if !empty(basepath) - let [base, bpath] = split(basepath, ':', 1) + let i = strridx(basepath, ':') + let [base, bpath] = [basepath[0:i-1], basepath[i+1:]] if base == diffbase return gitgutter#utility#shellescape(bpath) endif diff --git a/test/test_gitgutter.vim b/test/test_gitgutter.vim index 98bcb22..a9b2340 100644 --- a/test/test_gitgutter.vim +++ b/test/test_gitgutter.vim @@ -196,6 +196,20 @@ function Test_filename_with_equals() endfunction +function Test_filename_with_colon() + 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_with_square_brackets() call system('touch fix[tu]re.txt && git add fix[tu]re.txt') edit fix[tu]re.txt