diff --git a/lua/neogit/buffers/process/init.lua b/lua/neogit/buffers/process/init.lua index aa38db1ab..f71dd2ee3 100644 --- a/lua/neogit/buffers/process/init.lua +++ b/lua/neogit/buffers/process/init.lua @@ -104,7 +104,7 @@ function M:open() filetype = "NeogitConsole", bufhidden = "hide", open = false, - buftype = false, + buftype = "nofile", -- Use nofile to avoid swap file conflicts kind = config.values.preview_buffer.kind, after = function(buffer) buffer:open_terminal_channel() diff --git a/lua/neogit/process.lua b/lua/neogit/process.lua index fb0dd2c8a..344a9c481 100644 --- a/lua/neogit/process.lua +++ b/lua/neogit/process.lua @@ -327,8 +327,23 @@ function Process:spawn(cb) if self.buffer and not self.suppress_console then self.buffer:append(string.format("Process exited with code: %d", code)) + end + + -- Handle git hook failures and other errors + if code > 0 then + local should_show_error = self.on_error(res) + local is_hook_failure = self.git_hook and code > 0 + + -- For git hook failures, always show the Git Console + if is_hook_failure then + -- Simply show the existing buffer with the git hook output + if self.buffer then + self.buffer:show() + end + end - if not self.buffer:is_visible() and code > 0 and self.on_error(res) then + -- Handle normal error display logic + if should_show_error and not is_hook_failure then local output = {} local start = math.max(#res.stderr - 16, 1) for i = start, math.min(#res.stderr, start + 16) do @@ -339,19 +354,21 @@ function Process:spawn(cb) local message = string.format("%s:\n\n%s", mask_command(table.concat(self.cmd, " ")), table.concat(output, "\n")) notification.warn(message) - elseif config.values.auto_show_console_on == "error" then + elseif config.values.auto_show_console_on == "error" and self.buffer then self.buffer:show() end end + end - if - not self.user_command - and config.values.auto_close_console - and self.buffer:is_visible() - and code == 0 - then - self.buffer:close() - end + -- Close console on success if configured + if + self.buffer + and not self.user_command + and config.values.auto_close_console + and self.buffer:is_visible() + and code == 0 + then + self.buffer:close() end self.stdin = nil