From 5bb8ec4824e237b8829cf2b6bb80d4b052841ba7 Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 23 Jul 2024 22:14:48 +0200 Subject: [PATCH 1/7] Remove "verbose" flag - unused --- lua/neogit/lib/git/cli.lua | 3 --- lua/neogit/lib/git/index.lua | 1 - lua/neogit/lib/git/merge.lua | 2 +- lua/neogit/lib/git/rebase.lua | 2 +- lua/neogit/process.lua | 1 - 5 files changed, 2 insertions(+), 7 deletions(-) diff --git a/lua/neogit/lib/git/cli.lua b/lua/neogit/lib/git/cli.lua index b1d9458e..0d986be2 100644 --- a/lua/neogit/lib/git/cli.lua +++ b/lua/neogit/lib/git/cli.lua @@ -967,14 +967,12 @@ local function new_builder(subcommand) cwd = git.repo.git_root, env = state.env, pty = state.in_pty, - verbose = opts.verbose, on_error = opts.on_error, } end local function make_options(options) local opts = vim.tbl_extend("keep", (options or {}), { - verbose = false, hidden = false, trim = true, remove_ansi = true, @@ -998,7 +996,6 @@ local function new_builder(subcommand) call = function(options) local opts = make_options(options) local p = to_process { - verbose = opts.verbose, on_error = function(res) -- When aborting, don't alert the user. exit(1) is expected. for _, line in ipairs(res.stdout) do diff --git a/lua/neogit/lib/git/index.lua b/lua/neogit/lib/git/index.lua index fdc7fc9a..d929d08b 100644 --- a/lua/neogit/lib/git/index.lua +++ b/lua/neogit/lib/git/index.lua @@ -150,7 +150,6 @@ function M.update() require("neogit.process") .new({ cmd = { "git", "update-index", "-q", "--refresh" }, - verbose = false, on_error = function(_) return false end, diff --git a/lua/neogit/lib/git/merge.lua b/lua/neogit/lib/git/merge.lua index 6e1cc05c..df74f707 100644 --- a/lua/neogit/lib/git/merge.lua +++ b/lua/neogit/lib/git/merge.lua @@ -8,7 +8,7 @@ local a = require("plenary.async") local M = {} local function merge_command(cmd) - return cmd.env(client.get_envs_git_editor()).call { verbose = true, pty = true } + return cmd.env(client.get_envs_git_editor()).call { pty = true } end local function fire_merge_event(data) diff --git a/lua/neogit/lib/git/rebase.lua b/lua/neogit/lib/git/rebase.lua index 3715e83f..a5257a47 100644 --- a/lua/neogit/lib/git/rebase.lua +++ b/lua/neogit/lib/git/rebase.lua @@ -11,7 +11,7 @@ local function fire_rebase_event(data) end local function rebase_command(cmd) - return cmd.env(client.get_envs_git_editor()).call { verbose = true, long = true, pty = true } + return cmd.env(client.get_envs_git_editor()).call { long = true, pty = true } end ---Instant rebase. This is a way to rebase without using the interactive editor diff --git a/lua/neogit/process.lua b/lua/neogit/process.lua index b8c40a98..cd98e854 100644 --- a/lua/neogit/process.lua +++ b/lua/neogit/process.lua @@ -20,7 +20,6 @@ end ---@field cmd string[] ---@field cwd string|nil ---@field env table|nil ----@field verbose boolean If true, stdout will be written to the console buffer ---@field result ProcessResult|nil ---@field job number|nil ---@field stdin number|nil From f7776e7f133ea540dca66fa520a669f24ae67e2e Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 23 Jul 2024 23:43:01 +0200 Subject: [PATCH 2/7] remove last verbose flag --- lua/neogit/client.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lua/neogit/client.lua b/lua/neogit/client.lua index 85fa3f91..23581d87 100644 --- a/lua/neogit/client.lua +++ b/lua/neogit/client.lua @@ -147,8 +147,7 @@ function M.wrap(cmd, opts) end logger.debug("[CLIENT] Calling editor command") - local result = - cmd.env(M.get_envs_git_editor(opts.show_diff)).call { verbose = true, pty = opts.interactive } + local result = cmd.env(M.get_envs_git_editor(opts.show_diff)).call { pty = opts.interactive } a.util.scheduler() logger.debug("[CLIENT] DONE editor command") From 9f4f4d172bb0a65b34abd2cf88a6d8ca18ab3576 Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 23 Jul 2024 23:55:20 +0200 Subject: [PATCH 3/7] Fix notifications - print stdout on git error. --- lua/neogit/lib/util.lua | 2 +- lua/neogit/process.lua | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lua/neogit/lib/util.lua b/lua/neogit/lib/util.lua index 8e696853..621e4940 100644 --- a/lua/neogit/lib/util.lua +++ b/lua/neogit/lib/util.lua @@ -582,7 +582,7 @@ end -- from: https://stackoverflow.com/questions/48948630/lua-ansi-escapes-pattern local pattern_1 = "[\27\155][][()#;?%d]*[A-PRZcf-ntqry=><~]" -local pattern_2 = "[\r\n\04\08]" +local pattern_2 = "[\r\04\08]" local BLANK = "" local gsub = string.gsub diff --git a/lua/neogit/process.lua b/lua/neogit/process.lua index cd98e854..57c17881 100644 --- a/lua/neogit/process.lua +++ b/lua/neogit/process.lua @@ -277,13 +277,13 @@ function Process:spawn(cb) if not self.buffer:is_visible() and code > 0 and self.on_error(res) then local output = {} - local start = math.max(#res.output - 16, 1) - for i = start, math.min(#res.output, start + 16) do - insert(output, " " .. res.output[i]) + local start = math.max(#res.stderr - 16, 1) + for i = start, math.min(#res.stderr, start + 16) do + insert(output, "> " .. res.stderr[i]) end local message = string.format( - "%s:\n\n%s\n\nAn error occurred.", + "%s:\n\n%s", mask_command(table.concat(self.cmd, " ")), table.concat(output, "\n") ) From bce68565b0b520bfb81e3d609dc0387617415ad1 Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 23 Jul 2024 23:56:26 +0200 Subject: [PATCH 4/7] Remove schedule call - not needed --- lua/neogit/lib/git/merge.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/lua/neogit/lib/git/merge.lua b/lua/neogit/lib/git/merge.lua index df74f707..77d43148 100644 --- a/lua/neogit/lib/git/merge.lua +++ b/lua/neogit/lib/git/merge.lua @@ -2,8 +2,6 @@ local client = require("neogit.client") local git = require("neogit.lib.git") local notification = require("neogit.lib.notification") -local a = require("plenary.async") - ---@class NeogitGitMerge local M = {} @@ -16,7 +14,6 @@ local function fire_merge_event(data) end function M.merge(branch, args) - a.util.scheduler() local result = merge_command(git.cli.merge.args(branch).arg_list(args)) if result.code ~= 0 then notification.error("Merging failed. Resolve conflicts before continuing") From ed69ed8a81d7d84b78ef6313936ddb713a61c882 Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 23 Jul 2024 23:57:56 +0200 Subject: [PATCH 5/7] lint --- lua/neogit/process.lua | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lua/neogit/process.lua b/lua/neogit/process.lua index 57c17881..879c9557 100644 --- a/lua/neogit/process.lua +++ b/lua/neogit/process.lua @@ -282,11 +282,8 @@ function Process:spawn(cb) insert(output, "> " .. res.stderr[i]) end - local message = string.format( - "%s:\n\n%s", - mask_command(table.concat(self.cmd, " ")), - table.concat(output, "\n") - ) + local message = + string.format("%s:\n\n%s", mask_command(table.concat(self.cmd, " ")), table.concat(output, "\n")) notification.warn(message) end From 32ee024aa34755f0deab8e9016b9b3f9a621a23a Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 24 Jul 2024 00:00:48 +0200 Subject: [PATCH 6/7] Escape Ansi codes here so newlines added later are left alone --- lua/neogit/lib/notification.lua | 6 +----- lua/neogit/lib/util.lua | 2 +- lua/neogit/process.lua | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lua/neogit/lib/notification.lua b/lua/neogit/lib/notification.lua index 824b579a..bf505465 100644 --- a/lua/neogit/lib/notification.lua +++ b/lua/neogit/lib/notification.lua @@ -11,11 +11,7 @@ local function create(message, level, opts) end vim.schedule(function() - vim.notify( - util.remove_ansi_escape_codes(message), - level, - { title = "Neogit", icon = config.values.notification_icon } - ) + vim.notify(message, level, { title = "Neogit", icon = config.values.notification_icon }) end) end diff --git a/lua/neogit/lib/util.lua b/lua/neogit/lib/util.lua index 621e4940..8e696853 100644 --- a/lua/neogit/lib/util.lua +++ b/lua/neogit/lib/util.lua @@ -582,7 +582,7 @@ end -- from: https://stackoverflow.com/questions/48948630/lua-ansi-escapes-pattern local pattern_1 = "[\27\155][][()#;?%d]*[A-PRZcf-ntqry=><~]" -local pattern_2 = "[\r\04\08]" +local pattern_2 = "[\r\n\04\08]" local BLANK = "" local gsub = string.gsub diff --git a/lua/neogit/process.lua b/lua/neogit/process.lua index 879c9557..3c853d1f 100644 --- a/lua/neogit/process.lua +++ b/lua/neogit/process.lua @@ -279,7 +279,7 @@ function Process:spawn(cb) local output = {} local start = math.max(#res.stderr - 16, 1) for i = start, math.min(#res.stderr, start + 16) do - insert(output, "> " .. res.stderr[i]) + insert(output, "> " .. util.remove_ansi_escape_codes(res.stderr[i])) end local message = From 1fb813364e2e6dddc38dae9ba232820ee9e6fca7 Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 24 Jul 2024 00:02:23 +0200 Subject: [PATCH 7/7] Remove util --- lua/neogit/lib/notification.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/neogit/lib/notification.lua b/lua/neogit/lib/notification.lua index bf505465..67ae4559 100644 --- a/lua/neogit/lib/notification.lua +++ b/lua/neogit/lib/notification.lua @@ -1,6 +1,5 @@ local M = {} local config = require("neogit.config") -local util = require("neogit.lib.util") ---@param message string message to send ---@param level integer vim.log.levels.X