diff --git a/lua/gitlab/actions/common.lua b/lua/gitlab/actions/common.lua index a6734d26..a2caed0d 100644 --- a/lua/gitlab/actions/common.lua +++ b/lua/gitlab/actions/common.lua @@ -293,6 +293,13 @@ M.jump_to_file = function(tree) u.notify("This comment was not left on a particular location", vim.log.levels.WARN) return end + if vim.fn.filereadable(root_node.file_name) == 0 then + u.notify( + string.format("The file %s for which the comment was made doesn't exist in HEAD.", root_node.file_name), + vim.log.levels.WARN + ) + return + end vim.cmd.tabnew() local line_number = get_new_line(root_node) or get_old_line(root_node) if line_number == nil then diff --git a/lua/gitlab/reviewer/init.lua b/lua/gitlab/reviewer/init.lua index c5b103be..c4837df3 100644 --- a/lua/gitlab/reviewer/init.lua +++ b/lua/gitlab/reviewer/init.lua @@ -109,7 +109,6 @@ M.jump = function(file_name, line_number, new_buffer) return end vim.api.nvim_set_current_tabpage(M.tabnr) - vim.cmd("DiffviewFocusFiles") local view = diffview_lib.get_current_view() if view == nil then u.notify("Could not find Diffview view", vim.log.levels.ERROR) @@ -120,6 +119,13 @@ M.jump = function(file_name, line_number, new_buffer) local file = List.new(files):find(function(file) return file.path == file_name end) + if file == nil then + u.notify( + string.format("The file %s for which the comment was made doesn't exist in HEAD.", file_name), + vim.log.levels.WARN + ) + return + end async.await(view:set_file(file)) local layout = view.cur_layout