fix: git sub module path

it will broken with
fugitive:///home/wind/projects/abcdef/.git/modules/web-components//198faedae29cd87cc8f839e22d347e6c6e0ce17f/src/app/index.html
This commit is contained in:
windwp 2021-04-15 08:58:19 +07:00 committed by Lewis Russell
parent 56bd673932
commit 87a12bddd0
2 changed files with 26 additions and 10 deletions

18
lua/gitsigns.lua generated
View File

@ -414,11 +414,19 @@ local function get_buf_path(bufnr)
if vim.startswith(file, 'fugitive://') and vim.wo.diff == false then
local orig_path = file
file = file:gsub('^fugitive:', ''):gsub('%.git/+%x-/', '')
file = uv.fs_realpath(file)
local commit = orig_path:match('fugitive.*/(%x-)/')
dprint(("Fugitive buffer for file '%s' from path '%s'"):format(file, orig_path), bufnr)
return file, commit
local _, _, root_path, sub_module_path, commit, real_path =
file:find([[^fugitive://(.*)/%.git(.*)/(%x-)/(.*)]])
if root_path then
sub_module_path = sub_module_path:gsub("^/modules", "")
file = root_path .. sub_module_path .. real_path
file = uv.fs_realpath(file)
dprint(("Fugitive buffer for file '%s' from path '%s'"):format(file, orig_path), bufnr)
if file then
return file, commit
else
file = orig_path
end
end
end
return file

View File

@ -414,11 +414,19 @@ local function get_buf_path(bufnr: integer): string, string
if vim.startswith(file, 'fugitive://') and vim.wo.diff == false then
local orig_path = file
file = file:gsub('^fugitive:',''):gsub('%.git/+%x-/', '')
file = uv.fs_realpath(file)
local commit = orig_path:match('fugitive.*/(%x-)/')
dprint(("Fugitive buffer for file '%s' from path '%s'"):format(file, orig_path), bufnr)
return file, commit
local _,_, root_path, sub_module_path, commit, real_path =
file:find([[^fugitive://(.*)/%.git(.*)/(%x-)/(.*)]])
if root_path then
sub_module_path = sub_module_path:gsub("^/modules", "")
file = root_path .. sub_module_path .. real_path
file = uv.fs_realpath(file)
dprint(("Fugitive buffer for file '%s' from path '%s'"):format(file, orig_path), bufnr)
if file then
return file, commit
else
file = orig_path
end
end
end
return file