Added command to open diffview
This commit is contained in:
@@ -191,6 +191,7 @@ M.build_note = function(note)
|
||||
end
|
||||
local noteHeader = "@" ..
|
||||
note.author.username .. " on " .. u.format_date(note.created_at)
|
||||
|
||||
local note_node = NuiTree.Node(
|
||||
{
|
||||
text = noteHeader,
|
||||
|
||||
@@ -100,6 +100,7 @@ M.setup = function(args, build_only)
|
||||
end
|
||||
|
||||
keymaps.set_keymap_keys(args.keymaps)
|
||||
keymaps.set_keymaps()
|
||||
end
|
||||
|
||||
M.current_file_path = function()
|
||||
|
||||
@@ -19,4 +19,30 @@ M.set_keymap_keys = function(keyTable)
|
||||
state.keymaps = u.merge_tables(state.keymaps, keyTable)
|
||||
end
|
||||
|
||||
M.set_keymaps = function()
|
||||
local ok, _ = pcall(require, "diffview")
|
||||
vim.keymap.set("n", state.keymaps.review.toggle, function()
|
||||
if not ok then
|
||||
require("notify")("You must have diffview.nvim installed to use this command!", "error")
|
||||
return
|
||||
end
|
||||
local isDiff = vim.fn.getwinvar(nil, "&diff")
|
||||
local bufName = vim.api.nvim_buf_get_name(0)
|
||||
local has_develop = u.branch_exists("main") -- TODO: Write this function
|
||||
if not has_develop then
|
||||
require("notify")('No ' .. state.BASE_BRANCH .. ' branch, cannot review.', "error")
|
||||
return
|
||||
end
|
||||
if isDiff ~= 0 or u.string_starts(bufName, "diff") then
|
||||
vim.cmd.tabclose()
|
||||
vim.cmd.tabprev()
|
||||
else
|
||||
vim.cmd.DiffviewOpen(state.BASE_BRANCH)
|
||||
u.press_enter()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
|
||||
return M
|
||||
|
||||
@@ -23,6 +23,9 @@ M.keymaps = {
|
||||
focus_prev = { "k", "<Up>", "<S-Tab>" },
|
||||
close = { "<Esc>", "<C-c>" },
|
||||
submit = { "<CR>", "<Space>" },
|
||||
},
|
||||
review = {
|
||||
toggle = "<leader>glt"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,20 @@ local function get_git_root()
|
||||
end
|
||||
end
|
||||
|
||||
local branch_exists = function(b)
|
||||
local is_git_branch = io.popen("git rev-parse --is-inside-work-tree 2>/dev/null"):read("*a")
|
||||
if is_git_branch == "true\n" then
|
||||
for line in io.popen("git branch 2>/dev/null"):lines() do
|
||||
line = line:gsub("%s+", "")
|
||||
if line == b then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
local function get_relative_file_path()
|
||||
local git_root = get_git_root()
|
||||
if git_root ~= nil then
|
||||
@@ -118,6 +132,7 @@ end
|
||||
|
||||
|
||||
local function jump_to_file(filename, line_number)
|
||||
if line_number == nil then line_number = 1 end
|
||||
vim.api.nvim_command("wincmd l")
|
||||
local bufnr = vim.fn.bufnr(filename)
|
||||
if bufnr ~= -1 then
|
||||
@@ -244,5 +259,6 @@ M.create_popup_state = create_popup_state
|
||||
M.exit = exit
|
||||
M.read_file = read_file
|
||||
M.split_diff_view_filename = split_diff_view_filename
|
||||
M.branch_exists = branch_exists
|
||||
M.P = P
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user