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.
This commit is contained in:
tmwatchanan 2026-06-20 18:43:09 +07:00
parent a2b21978c6
commit 799deabfef
No known key found for this signature in database
GPG key ID: F4D43507B7A7F4AC
2 changed files with 27 additions and 1 deletions

View file

@ -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

View file

@ -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()