Skip to content

Commit

Permalink
fix: use fugitive functions to parse fugitive:// url
Browse files Browse the repository at this point in the history
Fixes #686
  • Loading branch information
rosds authored and lewis6991 committed Dec 15, 2022
1 parent d076301 commit ad5df55
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
15 changes: 8 additions & 7 deletions lua/gitsigns.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions teal/gitsigns.tl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions types/vim.d.tl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ local record M

record g
gitsigns_head: string
loaded_fugitive: integer
end

record v
Expand Down
3 changes: 3 additions & 0 deletions types/vim/fn.d.tl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ad5df55

Please sign in to comment.