From 36184e5a58192ebca1d2fe77915e7563107fa482 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Sun, 4 Apr 2021 20:30:45 +0100 Subject: [PATCH] Fix: Don't error on untracked files with blame Fixes #123 --- lua/gitsigns.lua | 2 +- lua/gitsigns/git.lua | 4 ++++ teal/gitsigns.tl | 2 +- teal/gitsigns/git.tl | 4 ++++ test/gitsigns_spec.lua | 16 ++++++++++++++++ 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lua/gitsigns.lua b/lua/gitsigns.lua index c575833..bfb3303 100644 --- a/lua/gitsigns.lua +++ b/lua/gitsigns.lua @@ -749,7 +749,7 @@ end local _current_line_blame = void_async(function() local bufnr = current_buf() local bcache = cache[bufnr] - if not bcache then + if not bcache or not bcache.object_name then return end diff --git a/lua/gitsigns/git.lua b/lua/gitsigns/git.lua index 005f3f1..5bb299c 100644 --- a/lua/gitsigns/git.lua +++ b/lua/gitsigns/git.lua @@ -195,6 +195,10 @@ M.run_blame = a.wrap(function( end, on_exit = function() local ret = {} + if #results == 0 then + callback({}) + return + end local header = vim.split(table.remove(results, 1), ' ') ret.sha = header[1] ret.abbrev_sha = string.sub(ret.sha, 1, 8) diff --git a/teal/gitsigns.tl b/teal/gitsigns.tl index efe0f14..ecba26a 100644 --- a/teal/gitsigns.tl +++ b/teal/gitsigns.tl @@ -749,7 +749,7 @@ end local _current_line_blame = void_async(function() local bufnr = current_buf() local bcache = cache[bufnr] - if not bcache then + if not bcache or not bcache.object_name then return end diff --git a/teal/gitsigns/git.tl b/teal/gitsigns/git.tl index a031152..36babed 100644 --- a/teal/gitsigns/git.tl +++ b/teal/gitsigns/git.tl @@ -195,6 +195,10 @@ M.run_blame = a.wrap(function( end, on_exit = function() local ret: {string:any} = {} + if #results == 0 then + callback({}) + return + end local header = vim.split(table.remove(results, 1), ' ') ret.sha = header[1] ret.abbrev_sha = string.sub(ret.sha as string, 1, 8) diff --git a/test/gitsigns_spec.lua b/test/gitsigns_spec.lua index 743dd2e..e55642f 100644 --- a/test/gitsigns_spec.lua +++ b/test/gitsigns_spec.lua @@ -436,6 +436,22 @@ describe('gitsigns', function() end) end) + describe('current line blame', function() + it('doesn\'t error on untracked files', function() + command("set updatetime=1") + init(true) + screen:detach() + screen:attach({ext_messages=true}) + config.current_line_blame = true + exec_lua('gs.setup(...)', config) + sleep(20) + edit(newfile) + feed("iline") + command("write") + screen:expect{messages = { { content = { { "<" } }, kind = "" } } } + end) + end) + local function testsuite(advanced_features) return function() before_each(function()