2022-12-24 18:27:29 +08: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 15:13:43 +08:00
|
|
|
local args
|
2022-12-24 18:27:29 +08:00
|
|
|
if diff.commit then
|
2023-01-09 15:05:32 +08:00
|
|
|
args = ("-C=%s"):format(plugin.dir) .. " " .. diff.commit .. "^!"
|
2022-12-24 18:27:29 +08:00
|
|
|
else
|
2023-01-04 15:13:43 +08:00
|
|
|
args = ("-C=%s"):format(plugin.dir) .. " " .. diff.from .. ".." .. diff.to
|
2022-12-24 18:27:29 +08:00
|
|
|
end
|
2023-01-04 15:13:43 +08:00
|
|
|
vim.cmd("DiffviewOpen " .. args)
|
2022-12-24 18:27:29 +08:00
|
|
|
end,
|
|
|
|
|
|
|
|
---@type LazyDiffFun
|
|
|
|
git = function(plugin, diff)
|
2022-12-25 20:45:56 +08:00
|
|
|
local cmd = { "git" }
|
2022-12-24 18:27:29 +08:00
|
|
|
if diff.commit then
|
2022-12-25 20:45:56 +08:00
|
|
|
cmd[#cmd + 1] = "show"
|
2022-12-24 18:27:29 +08:00
|
|
|
cmd[#cmd + 1] = diff.commit
|
|
|
|
else
|
2022-12-25 20:45:56 +08:00
|
|
|
cmd[#cmd + 1] = "diff"
|
2022-12-24 18:27:29 +08:00
|
|
|
cmd[#cmd + 1] = diff.from
|
|
|
|
cmd[#cmd + 1] = diff.to
|
|
|
|
end
|
2023-01-06 00:36:01 +08:00
|
|
|
Util.float_cmd(cmd, { cwd = plugin.dir, filetype = "git" })
|
2022-12-24 18:27:29 +08:00
|
|
|
end,
|
|
|
|
|
|
|
|
---@type LazyDiffFun
|
|
|
|
terminal_git = function(plugin, diff)
|
2022-12-25 20:45:56 +08:00
|
|
|
local cmd = { "git" }
|
2022-12-24 18:27:29 +08:00
|
|
|
if diff.commit then
|
2022-12-25 20:45:56 +08:00
|
|
|
cmd[#cmd + 1] = "show"
|
2022-12-24 18:27:29 +08:00
|
|
|
cmd[#cmd + 1] = diff.commit
|
|
|
|
else
|
2022-12-25 20:45:56 +08:00
|
|
|
cmd[#cmd + 1] = "diff"
|
2022-12-24 18:27:29 +08:00
|
|
|
cmd[#cmd + 1] = diff.from
|
|
|
|
cmd[#cmd + 1] = diff.to
|
|
|
|
end
|
2023-01-06 00:36:01 +08:00
|
|
|
Util.float_term(cmd, { cwd = plugin.dir, interactive = false, env = { PAGER = "cat" } })
|
2022-12-24 18:27:29 +08:00
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
return M
|