Handle file moves for quickfix

Do not assume the new name (`fnamer`) is the same length as the old
name (`fnamel`).

Also use the new name rather than the old name when populating the
quickfix list.

See #872.
This commit is contained in:
Andy Stewart
2023-11-10 12:03:07 +00:00
parent 986228fa89
commit 4e262693a5

View File

@@ -222,13 +222,11 @@ function! gitgutter#quickfix(current_file)
let lnum = 0 let lnum = 0
for line in diff for line in diff
if line =~ '^diff --git [^"]' if line =~ '^diff --git [^"]'
let paths = line[11:] let [fnamel, fnamer] = split(line)[2:3]
let mid = (len(paths) - 1) / 2 let fname = fnamel ==# fnamer ? fnamer : fnamer[2:]
let [fnamel, fnamer] = [paths[:mid-1], paths[mid+1:]]
let fname = fnamel ==# fnamer ? fnamel : fnamel[2:]
elseif line =~ '^diff --git "' elseif line =~ '^diff --git "'
let [_, fnamel, _, fnamer] = split(line, '"') let [_, fnamel, _, fnamer] = split(line, '"')
let fname = fnamel ==# fnamer ? fnamel : fnamel[2:] let fname = fnamel ==# fnamer ? fnamer : fnamer[2:]
elseif line =~ '^diff --cc [^"]' elseif line =~ '^diff --cc [^"]'
let fname = line[10:] let fname = line[10:]
elseif line =~ '^diff --cc "' elseif line =~ '^diff --cc "'