mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-13 17:16:23 -04:00
Hook and push output is easy to read in lazygit but hard to reuse elsewhere. Parse git output blocks from the command log view so copies match what is shown, include the action and command above each block, and avoid logging clipboard operations back into the stream.
90 lines
1.9 KiB
Go
90 lines
1.9 KiB
Go
package gui
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
const gitOutputHeader = "Git output:"
|
|
|
|
func TestGitOutputBlocksFromCommandLogLines(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
lines := []string{
|
|
"Push",
|
|
" git push",
|
|
"",
|
|
gitOutputHeader,
|
|
"line1",
|
|
"line2",
|
|
}
|
|
|
|
assert.Equal(t, []string{"Push\n git push\n\nGit output:\nline1\nline2"}, gitOutputBlocksFromCommandLogLines(lines, gitOutputHeader))
|
|
}
|
|
|
|
func TestGitOutputBlocksSkipCopyNotifications(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
lines := []string{
|
|
"Push",
|
|
" git push",
|
|
gitOutputHeader,
|
|
"hook line",
|
|
" Copying 'hook line' to clipboard",
|
|
"hook line 2",
|
|
}
|
|
|
|
assert.Equal(t, []string{"Push\n git push\n\nGit output:\nhook line\nhook line 2"}, gitOutputBlocksFromCommandLogLines(lines, gitOutputHeader))
|
|
}
|
|
|
|
func TestGitOutputBlocksEndAtNextCommandLogEntry(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
lines := []string{
|
|
"Push",
|
|
" git push",
|
|
gitOutputHeader,
|
|
"first command output",
|
|
"Stage file",
|
|
" git add foo",
|
|
"",
|
|
gitOutputHeader,
|
|
"second command output",
|
|
}
|
|
|
|
assert.Equal(t, []string{
|
|
"Push\n git push\n\nGit output:\nfirst command output",
|
|
"Stage file\n git add foo\n\nGit output:\nsecond command output",
|
|
}, gitOutputBlocksFromCommandLogLines(lines, gitOutputHeader))
|
|
}
|
|
|
|
func TestGitOutputBlocksMultipleBlocksJoined(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
lines := []string{
|
|
"Push",
|
|
" git push",
|
|
gitOutputHeader,
|
|
"first command",
|
|
"Pull",
|
|
" git pull",
|
|
gitOutputHeader,
|
|
"second command",
|
|
}
|
|
|
|
blocks := gitOutputBlocksFromCommandLogLines(lines, gitOutputHeader)
|
|
assert.Equal(t, "Push\n git push\n\nGit output:\nfirst command\n\nPull\n git pull\n\nGit output:\nsecond command", joinGitOutputBlocks(blocks))
|
|
}
|
|
|
|
func joinGitOutputBlocks(blocks []string) string {
|
|
result := ""
|
|
for i, block := range blocks {
|
|
if i > 0 {
|
|
result += "\n\n"
|
|
}
|
|
result += block
|
|
}
|
|
return result
|
|
}
|