diff --git a/lua/gitsigns.lua b/lua/gitsigns.lua index 291f4f1d..5ba7491a 100644 --- a/lua/gitsigns.lua +++ b/lua/gitsigns.lua @@ -74,17 +74,18 @@ M.detach = function(bufnr, _keep_signs) end local function parse_fugitive_uri(name) - local _, _, root_path, sub_module_path, commit, real_path = - name:find([[^fugitive://(.*)/%.git(.*/)/(%x-)/(.*)]]) + if vim.g.loaded_fugitive == 0 then + return + end + local path = vim.fn.FugitiveReal(name) + local result = vim.fn.FugitiveParse(name) + local commit = result[1]:match('([^:]+):.*') if commit == '0' then commit = nil end - if root_path then - sub_module_path = sub_module_path:gsub("^/modules", "") - name = root_path .. sub_module_path .. real_path - end - return name, commit + + return path, commit end local function parse_gitsigns_uri(name) diff --git a/teal/gitsigns.tl b/teal/gitsigns.tl index e6fa1b47..7d1a00b3 100644 --- a/teal/gitsigns.tl +++ b/teal/gitsigns.tl @@ -74,17 +74,18 @@ M.detach = function(bufnr: integer, _keep_signs: boolean) end local function parse_fugitive_uri(name: string): string, string - local _, _, root_path, sub_module_path, commit, real_path = - name:find([[^fugitive://(.*)/%.git(.*/)/(%x-)/(.*)]]) + if vim.g.loaded_fugitive == 0 then + return + end + local path = vim.fn.FugitiveReal(name) + local result = vim.fn.FugitiveParse(name) + local commit = result[1]:match('([^:]+):.*') if commit == '0' then - -- '0' means the index so cleat commit so we attach normally + -- '0' means the index so clear commit so we attach normally commit = nil end - if root_path then - sub_module_path = sub_module_path:gsub("^/modules", "") - name = root_path .. sub_module_path .. real_path - end - return name, commit + + return path, commit end local function parse_gitsigns_uri(name: string): string, string diff --git a/types/vim.d.tl b/types/vim.d.tl index 47e46301..727aafa1 100644 --- a/types/vim.d.tl +++ b/types/vim.d.tl @@ -85,6 +85,7 @@ local record M record g gitsigns_head: string + loaded_fugitive: integer end record v diff --git a/types/vim/fn.d.tl b/types/vim/fn.d.tl index acbedc7f..7b709d36 100644 --- a/types/vim/fn.d.tl +++ b/types/vim/fn.d.tl @@ -74,6 +74,9 @@ local record M systemlist: function({string}): {string} tempname: function(): string type: function(any): integer + + FugitiveReal: function(...: any): string + FugitiveParse: function(...: any): {string, string} end return M