Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: gitsigns in fugitive buffer not visible #460

Merged
merged 1 commit into from
Jan 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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