Fix the fix for colons in basepath

Commit 84bc2d6 tried to handle basepath values where the path contained
colons (see #877).  However the fix had two (!) bugs.

- It used strridx() to find the colon separating the diffbase and the
  path; it should have used stridx() because the base comes first.
- It used substring indexes incorrectly: foo[0:-1] returns the whole of
  foo, not an empty string (:help exr-[:]).

Closes #878.
This commit is contained in:
Andy Stewart
2024-01-05 12:43:02 +00:00
parent 84bc2d68c0
commit 67ef116100

View File

@@ -252,8 +252,14 @@ function! gitgutter#utility#base_path(bufnr)
" If we already know the original path at this diff base, return it. " If we already know the original path at this diff base, return it.
let basepath = gitgutter#utility#getbufvar(a:bufnr, 'basepath', '') let basepath = gitgutter#utility#getbufvar(a:bufnr, 'basepath', '')
if !empty(basepath) if !empty(basepath)
let i = strridx(basepath, ':') " basepath is diffbase:path
let [base, bpath] = [basepath[0:i-1], basepath[i+1:]] " Note that path can also contain colons.
" List destructuring / unpacking where the remaining items are assigned
" to a single variable (:help let-unpack) is only available in v8.2.0540.
let parts = split(basepath, ':', 1)
let base = parts[0]
let bpath = join(parts[1:], ':')
if base == diffbase if base == diffbase
return gitgutter#utility#shellescape(bpath) return gitgutter#utility#shellescape(bpath)
endif endif