From fda04337db829042d6ff00e204eb33e305decd22 Mon Sep 17 00:00:00 2001 From: Oscar Wallberg Date: Sat, 9 May 2026 00:42:26 +0200 Subject: [PATCH] refactor(git): keep routine success output out of :messages --- lua/git/cmd.lua | 2 +- lua/git/commit.lua | 2 +- test/git/cmd_test.lua | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/lua/git/cmd.lua b/lua/git/cmd.lua index f4d4d77..6ac16a5 100644 --- a/lua/git/cmd.lua +++ b/lua/git/cmd.lua @@ -238,7 +238,7 @@ local function run_to_messages(r, args) ) end if #chunks > 0 then - vim.api.nvim_echo(chunks, true, {}) + vim.api.nvim_echo(chunks, failed or err ~= "", {}) end end diff --git a/lua/git/commit.lua b/lua/git/commit.lua index 584ff48..92fbdc8 100644 --- a/lua/git/commit.lua +++ b/lua/git/commit.lua @@ -72,7 +72,7 @@ function M.commit(opts) end local out = vim.trim(result.stdout or "") if out ~= "" then - util.info("%s", out) + vim.api.nvim_echo({ { out } }, false, {}) end end) end diff --git a/test/git/cmd_test.lua b/test/git/cmd_test.lua index df69f72..0a050d4 100644 --- a/test/git/cmd_test.lua +++ b/test/git/cmd_test.lua @@ -509,6 +509,41 @@ local function has_status(calls, status) return false end +---@param calls { history: boolean }[] +---@return boolean +local function any_history(calls) + for _, c in ipairs(calls) do + if c.history then + return true + end + end + return false +end + +t.test("quiet :G success does not add to :messages history", function() + make_repo({ a = "x" }) + with_echo_stub(function(calls) + cmd.run({ "config", "user.email" }) + t.falsy(any_history(calls), "success path must not write history") + end) +end) + +t.test("quiet :G silent failure adds 'git exited N' to history", function() + make_repo({ a = "x" }) + with_echo_stub(function(calls) + cmd.run({ "config", "--get", "nonexistent.foo.bar" }) + t.truthy(any_history(calls), "failure path must write history") + end) +end) + +t.test("quiet :G stderr failure adds error to history", function() + make_repo({ a = "x" }) + with_echo_stub(function(calls) + cmd.run({ "branch", "-d", "nonexistent-branch" }) + t.truthy(any_history(calls), "failure path must write history") + end) +end) + t.test("streaming :G fetch (no bang) does not open a window", function() make_repo({ a = "x" }) with_echo_stub(function(calls)