From 49675ff9841cd0558eb8e1b807068142d9fce0f1 Mon Sep 17 00:00:00 2001 From: Oscar Wallberg Date: Wed, 13 May 2026 01:16:09 +0200 Subject: [PATCH] feat(git): route :G! through the preview window --- lua/git/cmd.lua | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/lua/git/cmd.lua b/lua/git/cmd.lua index 4446a1a..e18ca3b 100644 --- a/lua/git/cmd.lua +++ b/lua/git/cmd.lua @@ -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 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