Skip to content

fix: show console when git hooks fail #1778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lua/neogit/buffers/process/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
37 changes: 27 additions & 10 deletions lua/neogit/process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading