feat: add submodule support for gitsigns urls

Fixes #1095
This commit is contained in:
Lewis Russell 2024-07-25 12:14:39 +01:00 committed by Lewis Russell
parent 6f8dbdbd41
commit f074844b60
2 changed files with 18 additions and 6 deletions

View file

@ -41,13 +41,25 @@ end
--- @return string buffer
--- @return string? commit
local function parse_gitsigns_uri(name)
-- TODO(lewis6991): Support submodules
--- @type any, any, string?, string?, string
local _, _, root_path, commit, rel_path = name:find([[^gitsigns://(.*)/%.git/(.*):(.*)]])
local _proto, head, tail = unpack(vim.split(name, '//'))
--- @type any, any, string?, string?
local _, _, root_path, sub_path = head:find([[(.*)/%.git(.*)]])
--- @type any, any, string?, string?
local _, _, commit, rel_path = tail:find([[(.*):(.*)]])
commit = util.norm_base(commit)
if root_path then
name = root_path .. '/' .. rel_path
if sub_path then
sub_path = sub_path:gsub('^/modules/', '')
name = string.format('%s/%s/%s', root_path, sub_path, rel_path)
else
name = string.format('%s/%s', root_path, rel_path)
end
end
return name, commit
end

View file

@ -25,9 +25,9 @@ local CacheEntry = M.CacheEntry
function CacheEntry:get_rev_bufname(rev, nofile)
rev = rev or self.git_obj.revision or ':0'
if nofile then
return string.format('gitsigns://%s/%s', self.git_obj.repo.gitdir, rev)
return string.format('gitsigns://%s//%s', self.git_obj.repo.gitdir, rev)
end
return string.format('gitsigns://%s/%s:%s', self.git_obj.repo.gitdir, rev, self.git_obj.relpath)
return string.format('gitsigns://%s//%s:%s', self.git_obj.repo.gitdir, rev, self.git_obj.relpath)
end
--- Invalidate any state dependent on the buffer content.