Skip to content

Commit

Permalink
fix: gitsigns in fugitive buffer not visible
Browse files Browse the repository at this point in the history
  • Loading branch information
lschwahn authored and lewis6991 committed Jan 29, 2022
1 parent 4a2d30f commit 73d068a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 26 deletions.
35 changes: 22 additions & 13 deletions lua/gitsigns.lua

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

35 changes: 22 additions & 13 deletions teal/gitsigns.tl
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,23 @@ M.detach = function(bufnr: integer, _keep_signs: boolean)
cache:destroy(bufnr)
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 root_path then
sub_module_path = sub_module_path:gsub("^/modules", "")
name = root_path .. sub_module_path .. real_path
end
return name, commit
end

if _TEST then
local path, commit = parse_fugitive_uri(
'fugitive:///home/path/to/project/.git//1b441b947c4bc9a59db428f229456619051dd133/subfolder/to/a/file.txt')
assert(path == '/home/path/to/project/subfolder/to/a/file.txt', string.format('GOT %s', path))
assert(commit == '1b441b947c4bc9a59db428f229456619051dd133', string.format('GOT %s', commit))
end

local function get_buf_path(bufnr: integer): string, string
local file =
uv.fs_realpath(api.nvim_buf_get_name(bufnr))
Expand All @@ -168,19 +185,11 @@ local function get_buf_path(bufnr: integer): string, string
end)

if vim.startswith(file, 'fugitive://') and vim.wo.diff == false then
local orig_path = file
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)
dprintf("Fugitive buffer for file '%s' from path '%s'", file, orig_path)
if file then
return file, commit
else
file = orig_path
end
local path, commit = parse_fugitive_uri(file)
dprintf("Fugitive buffer for file '%s' from path '%s'", path, file)
path = uv.fs_realpath(path)
if path then
return path, commit
end
end

Expand Down
13 changes: 13 additions & 0 deletions test/unit_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
local helpers = require('test.gs_helpers')
local exec_lua = helpers.exec_lua
local setup_gitsigns = helpers.setup_gitsigns
local clear = helpers.clear

describe('unit', function()
it('passes all _TEST blocks', function()
clear()
exec_lua('package.path = ...', package.path)
exec_lua('_TEST = true')
setup_gitsigns()
end)
end)
2 changes: 2 additions & 0 deletions types/types.d.tl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
global _: any

global _TEST: boolean

global loadstring: function(string): (function(): any)

global unpack: function<T>({T}, number, number): T...
Expand Down

0 comments on commit 73d068a

Please sign in to comment.