2022-12-24 10:27:29 +00:00
|
|
|
local Util = require("lazy.util")
|
|
|
|
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
---@alias LazyDiff {commit:string} | {from:string, to:string}
|
|
|
|
---@alias LazyDiffFun fun(plugin:LazyPlugin, diff:LazyDiff)
|
|
|
|
|
|
|
|
M.handlers = {
|
|
|
|
|
|
|
|
---@type LazyDiffFun
|
|
|
|
browser = function(plugin, diff)
|
|
|
|
if plugin.url then
|
|
|
|
local url = plugin.url:gsub("%.git$", "")
|
|
|
|
if diff.commit then
|
|
|
|
Util.open(url .. "/commit/" .. diff.commit)
|
|
|
|
else
|
|
|
|
Util.open(url .. "/compare/" .. diff.from .. ".." .. diff.to)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Util.error("No url for " .. plugin.name)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
|
|
|
---@type LazyDiffFun
|
|
|
|
["diffview.nvim"] = function(plugin, diff)
|
2023-01-04 07:13:43 +00:00
|
|
|
local args
|
2022-12-24 10:27:29 +00:00
|
|
|
if diff.commit then
|
2023-01-04 07:13:43 +00:00
|
|
|
args = ("-C=%s"):format(plugin.dir) .. " " .. diff.commit
|
2022-12-24 10:27:29 +00:00
|
|
|
else
|
2023-01-04 07:13:43 +00:00
|
|
|
args = ("-C=%s"):format(plugin.dir) .. " " .. diff.from .. ".." .. diff.to
|
2022-12-24 10:27:29 +00:00
|
|
|
end
|
2023-01-04 07:13:43 +00:00
|
|
|
vim.cmd("DiffviewOpen " .. args)
|
2022-12-24 10:27:29 +00:00
|
|
|
end,
|
|
|
|
|
|
|
|
---@type LazyDiffFun
|
|
|
|
git = function(plugin, diff)
|
2022-12-25 12:45:56 +00:00
|
|
|
local cmd = { "git" }
|
2022-12-24 10:27:29 +00:00
|
|
|
if diff.commit then
|
2022-12-25 12:45:56 +00:00
|
|
|
cmd[#cmd + 1] = "show"
|
2022-12-24 10:27:29 +00:00
|
|
|
cmd[#cmd + 1] = diff.commit
|
|
|
|
else
|
2022-12-25 12:45:56 +00:00
|
|
|
cmd[#cmd + 1] = "diff"
|
2022-12-24 10:27:29 +00:00
|
|
|
cmd[#cmd + 1] = diff.from
|
|
|
|
cmd[#cmd + 1] = diff.to
|
|
|
|
end
|
|
|
|
Util.open_cmd(cmd, { cwd = plugin.dir, filetype = "git" })
|
|
|
|
end,
|
|
|
|
|
|
|
|
---@type LazyDiffFun
|
|
|
|
terminal_git = function(plugin, diff)
|
2022-12-25 12:45:56 +00:00
|
|
|
local cmd = { "git" }
|
2022-12-24 10:27:29 +00:00
|
|
|
if diff.commit then
|
2022-12-25 12:45:56 +00:00
|
|
|
cmd[#cmd + 1] = "show"
|
2022-12-24 10:27:29 +00:00
|
|
|
cmd[#cmd + 1] = diff.commit
|
|
|
|
else
|
2022-12-25 12:45:56 +00:00
|
|
|
cmd[#cmd + 1] = "diff"
|
2022-12-24 10:27:29 +00:00
|
|
|
cmd[#cmd + 1] = diff.from
|
|
|
|
cmd[#cmd + 1] = diff.to
|
|
|
|
end
|
|
|
|
Util.open_cmd(cmd, { cwd = plugin.dir, terminal = true, env = { PAGER = "cat" } })
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
return M
|