fix: blame blocked on non-git files
This commit is contained in:
@@ -37,4 +37,5 @@ Git line blame by mail.
|
|||||||
|
|
||||||
## 🚨 Known issues
|
## 🚨 Known issues
|
||||||
|
|
||||||
- [ ] Error on non-git files.
|
- [x] Error on non-git files.
|
||||||
|
- [ ] Performance: the autocmd should not be processed on non-git files, to this date it is simply not displayed but a `$ git log` is run.
|
||||||
|
|||||||
@@ -16,8 +16,15 @@ end
|
|||||||
|
|
||||||
local lineBlame = function(input_file_path, line_number, input_comma_separated_mail_list, blame_text, blame_highlight,
|
local lineBlame = function(input_file_path, line_number, input_comma_separated_mail_list, blame_text, blame_highlight,
|
||||||
blame_position)
|
blame_position)
|
||||||
|
local git_exit_code = os.execute("git log >/dev/null 2>&1")
|
||||||
|
|
||||||
|
if git_exit_code ~= 0 then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
local handler = io.popen("git blame -L " .. line_number .. "," .. line_number .. " -e " ..
|
local handler = io.popen("git blame -L " .. line_number .. "," .. line_number .. " -e " ..
|
||||||
input_file_path .. " | awk '{print $2}'")
|
input_file_path .. " | awk '{print $2}'")
|
||||||
|
|
||||||
if handler == nil then
|
if handler == nil then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@@ -30,7 +37,7 @@ local lineBlame = function(input_file_path, line_number, input_comma_separated_m
|
|||||||
|
|
||||||
local mail = string.match(result, "%(<(.+)>")
|
local mail = string.match(result, "%(<(.+)>")
|
||||||
|
|
||||||
if not mail then
|
if not mail or mail == nil or mail == "" then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -23,13 +23,23 @@ local function blameCurrentLine()
|
|||||||
"Monkey", vim.g.monkey_blame_position)
|
"Monkey", vim.g.monkey_blame_position)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function enableOnLine()
|
local function updateLineBlame()
|
||||||
vim.api.nvim_create_autocmd("CursorMoved", {
|
|
||||||
callback = function()
|
|
||||||
if vim.bo.buftype == nil or vim.bo.buftype == '' then
|
if vim.bo.buftype == nil or vim.bo.buftype == '' then
|
||||||
clearBlame()
|
clearBlame()
|
||||||
blameCurrentLine()
|
blameCurrentLine()
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function enableOnLine()
|
||||||
|
-- vim.api.nvim_create_autocmd("BufNew", {
|
||||||
|
-- callback = function(event)
|
||||||
|
-- local status = vim.api.nvim_buf_attach(event.buf, false, { on_changedtick = updateLineBlame })
|
||||||
|
-- -- status == false, for buffers that aren't bound to a file, because the buffer isn't loaded yet
|
||||||
|
-- end
|
||||||
|
-- })
|
||||||
|
vim.api.nvim_create_autocmd("CursorMoved", {
|
||||||
|
callback = function()
|
||||||
|
updateLineBlame()
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user