feat(git): route :G! through the preview window
This commit is contained in:
+15
-23
@@ -5,7 +5,7 @@ local util = require("git.core.util")
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
---@alias ow.Git.Cmd.Run fun(r: ow.Git.Repo, args: string[], bang: boolean)
|
---@alias ow.Git.Cmd.Run fun(r: ow.Git.Repo, args: string[])
|
||||||
|
|
||||||
---@type string[]?
|
---@type string[]?
|
||||||
local cached_cmds
|
local cached_cmds
|
||||||
@@ -258,7 +258,6 @@ end
|
|||||||
---@param r ow.Git.Repo
|
---@param r ow.Git.Repo
|
||||||
---@param args string[]
|
---@param args string[]
|
||||||
local function run_in_preview(r, args)
|
local function run_in_preview(r, args)
|
||||||
local prev_win = vim.api.nvim_get_current_win()
|
|
||||||
local pwin = find_or_create_preview_win()
|
local pwin = find_or_create_preview_win()
|
||||||
|
|
||||||
local buf = vim.api.nvim_create_buf(false, true)
|
local buf = vim.api.nvim_create_buf(false, true)
|
||||||
@@ -272,7 +271,6 @@ local function run_in_preview(r, args)
|
|||||||
cwd = r.worktree,
|
cwd = r.worktree,
|
||||||
term = true,
|
term = true,
|
||||||
})
|
})
|
||||||
vim.api.nvim_set_current_win(prev_win)
|
|
||||||
|
|
||||||
if job <= 0 then
|
if job <= 0 then
|
||||||
util.error("failed to start git job")
|
util.error("failed to start git job")
|
||||||
@@ -300,7 +298,7 @@ end
|
|||||||
---@param ft string
|
---@param ft string
|
||||||
---@return ow.Git.Cmd.Run
|
---@return ow.Git.Cmd.Run
|
||||||
local function in_split(ft)
|
local function in_split(ft)
|
||||||
return function(r, args, _bang)
|
return function(r, args)
|
||||||
run_in_split(r, args, ft)
|
run_in_split(r, args, ft)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -433,28 +431,17 @@ local function run_streaming(r, args)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param r ow.Git.Repo
|
|
||||||
---@param args string[]
|
|
||||||
---@param bang boolean
|
|
||||||
local function streaming_dispatch(r, args, bang)
|
|
||||||
if bang then
|
|
||||||
run_in_preview(r, args)
|
|
||||||
else
|
|
||||||
run_streaming(r, args)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
---@type table<string, ow.Git.Cmd.Run>
|
---@type table<string, ow.Git.Cmd.Run>
|
||||||
local HANDLERS = {
|
local HANDLERS = {
|
||||||
log = in_split("git"),
|
log = in_split("git"),
|
||||||
diff = in_split("git"),
|
diff = in_split("git"),
|
||||||
push = streaming_dispatch,
|
push = run_streaming,
|
||||||
fetch = streaming_dispatch,
|
fetch = run_streaming,
|
||||||
pull = streaming_dispatch,
|
pull = run_streaming,
|
||||||
clone = streaming_dispatch,
|
clone = run_streaming,
|
||||||
am = streaming_dispatch,
|
am = run_streaming,
|
||||||
["cherry-pick"] = streaming_dispatch,
|
["cherry-pick"] = run_streaming,
|
||||||
revert = streaming_dispatch,
|
revert = run_streaming,
|
||||||
}
|
}
|
||||||
|
|
||||||
---@param args string[]
|
---@param args string[]
|
||||||
@@ -484,6 +471,11 @@ function M.run(args, opts)
|
|||||||
|
|
||||||
local bang = opts and opts.bang or false
|
local bang = opts and opts.bang or false
|
||||||
|
|
||||||
|
if bang then
|
||||||
|
run_in_preview(r, args)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local sub = args[1]
|
local sub = args[1]
|
||||||
if sub == "commit" and not has_message(args) then
|
if sub == "commit" and not has_message(args) then
|
||||||
commit.commit({ args = vim.list_slice(args, 2) })
|
commit.commit({ args = vim.list_slice(args, 2) })
|
||||||
@@ -510,7 +502,7 @@ function M.run(args, opts)
|
|||||||
|
|
||||||
local handler = sub and HANDLERS[sub]
|
local handler = sub and HANDLERS[sub]
|
||||||
if handler then
|
if handler then
|
||||||
handler(r, args, bang)
|
handler(r, args)
|
||||||
else
|
else
|
||||||
run_to_messages(r, args)
|
run_to_messages(r, args)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user