From 799deabfefb76383694dbcc1a41c07418c538d93 Mon Sep 17 00:00:00 2001 From: tmwatchanan Date: Sat, 20 Jun 2026 18:43:09 +0700 Subject: [PATCH] Stop treating tool errors as command log boundaries when copying git output A non-indented error line followed by indented context matches the shape of an action plus command, so copied git output was truncated mid-block. Only treat the next line as a new log entry when it looks like a lazygit command rather than any indented text. --- pkg/gui/command_log_panel.go | 6 +++++- pkg/gui/command_log_panel_test.go | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/pkg/gui/command_log_panel.go b/pkg/gui/command_log_panel.go index be9fdc5b3..09edd14dd 100644 --- a/pkg/gui/command_log_panel.go +++ b/pkg/gui/command_log_panel.go @@ -146,12 +146,16 @@ func isStartOfNewCommandLogEntry(lines []string, i int) bool { if isCopyToClipboardLogLine(lines[j]) { continue } - return strings.HasPrefix(lines[j], " ") + return isLazygitCommandLogLine(lines[j]) } return false } +func isLazygitCommandLogLine(line string) bool { + return isCopyToClipboardLogLine(line) || strings.HasPrefix(line, " git ") +} + func (gui *Gui) LogCommand(cmdStr string, commandLine bool) { if gui.Views.Extras == nil { return diff --git a/pkg/gui/command_log_panel_test.go b/pkg/gui/command_log_panel_test.go index 3d2074017..485c731c6 100644 --- a/pkg/gui/command_log_panel_test.go +++ b/pkg/gui/command_log_panel_test.go @@ -38,6 +38,28 @@ func TestGitOutputBlocksIncludeIndentedStderr(t *testing.T) { assert.Equal(t, []string{"Push\n git push\n\nGit output:\n at foo.go:10\n at bar.go:20\nhook failed"}, gitOutputBlocksFromCommandLogLines(lines, gitOutputHeader)) } +func TestGitOutputBlocksIncludeToolErrorWithIndentedContext(t *testing.T) { + t.Parallel() + + lines := []string{ + "Push", + " git push", + gitOutputHeader, + "Error: validation failed", + " line 42: syntax error", + "more output", + "Stage file", + " git add foo", + gitOutputHeader, + "second command output", + } + + assert.Equal(t, []string{ + "Push\n git push\n\nGit output:\nError: validation failed\n line 42: syntax error\nmore output", + "Stage file\n git add foo\n\nGit output:\nsecond command output", + }, gitOutputBlocksFromCommandLogLines(lines, gitOutputHeader)) +} + func TestGitOutputBlocksSkipCopyNotifications(t *testing.T) { t.Parallel()