feat(git): route :G! through the preview window

This commit is contained in:
2026-05-13 01:16:09 +02:00
parent 8a88455f87
commit 49675ff984
+15 -23
View File
@@ -5,7 +5,7 @@ local util = require("git.core.util")
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[]?
local cached_cmds
@@ -258,7 +258,6 @@ end
---@param r ow.Git.Repo
---@param args string[]
local function run_in_preview(r, args)
local prev_win = vim.api.nvim_get_current_win()
local pwin = find_or_create_preview_win()
local buf = vim.api.nvim_create_buf(false, true)
@@ -272,7 +271,6 @@ local function run_in_preview(r, args)
cwd = r.worktree,
term = true,
})
vim.api.nvim_set_current_win(prev_win)
if job <= 0 then
util.error("failed to start git job")
@@ -300,7 +298,7 @@ end
---@param ft string
---@return ow.Git.Cmd.Run
local function in_split(ft)
return function(r, args, _bang)
return function(r, args)
run_in_split(r, args, ft)
end
end
@@ -433,28 +431,17 @@ local function run_streaming(r, args)
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>
local HANDLERS = {
log = in_split("git"),
diff = in_split("git"),
push = streaming_dispatch,
fetch = streaming_dispatch,
pull = streaming_dispatch,
clone = streaming_dispatch,
am = streaming_dispatch,
["cherry-pick"] = streaming_dispatch,
revert = streaming_dispatch,
push = run_streaming,
fetch = run_streaming,
pull = run_streaming,
clone = run_streaming,
am = run_streaming,
["cherry-pick"] = run_streaming,
revert = run_streaming,
}
---@param args string[]
@@ -484,6 +471,11 @@ function M.run(args, opts)
local bang = opts and opts.bang or false
if bang then
run_in_preview(r, args)
return
end
local sub = args[1]
if sub == "commit" and not has_message(args) then
commit.commit({ args = vim.list_slice(args, 2) })
@@ -510,7 +502,7 @@ function M.run(args, opts)
local handler = sub and HANDLERS[sub]
if handler then
handler(r, args, bang)
handler(r, args)
else
run_to_messages(r, args)
end