git: a creation gate that never writes history, a git tab with Paperclip's worktree scan, and a warning line in every pane

This commit is contained in:
Sam
2026-11-12 20:38:44 +11:00
parent f7b77f370f
commit c419de5b48
18 changed files with 2223 additions and 82 deletions

View File

@@ -8,6 +8,7 @@ import (
"strings"
"testing"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
@@ -56,3 +57,58 @@ func TestTruncateVisibleKeepsStylingAndWidth(t *testing.T) {
t.Fatalf("truncation should say it truncated: %q", got)
}
}
func TestBannerIsDrawnOnceAndKeepsTheHeight(t *testing.T) {
defer func(prev string) { bannerText = prev }(bannerText)
bannerText = "no worktrees — this folder is not a git repository"
const w, h = 80, 24
// A screen with three panels side by side, the way the board is drawn.
one := panel{title: "a", width: 26, height: h - 2}.render([]string{"x"})
two := panel{title: "b", width: 26, height: h - 2}.render([]string{"y"})
three := panel{title: "c", width: 26, height: h - 2}.render([]string{"z"})
inner := strings.Join([]string{
strings.Repeat(" ", w),
sideBySide(one, two, three),
"footer",
}, "\n")
b := bannerModel{inner: stubModel{view: inner}, width: w, height: h}
got := lines(b.View())
if len(got) != h {
t.Fatalf("got %d lines, want %d", len(got), h)
}
if n := strings.Count(strings.Join(got, "\n"), "no worktrees"); n != 1 {
t.Fatalf("the warning appears %d times, want once", n)
}
if !strings.Contains(strings.Join(got, "\n"), "footer") {
t.Fatal("the key hints were dropped; only the title line should give way")
}
if lipgloss.Width(got[0]) != w {
t.Fatalf("the warning line is %d wide, want %d", lipgloss.Width(got[0]), w)
}
}
type stubModel struct{ view string }
func (s stubModel) Init() tea.Cmd { return nil }
func (s stubModel) Update(tea.Msg) (tea.Model, tea.Cmd) { return s, nil }
func (s stubModel) View() string { return s.view }
func sideBySide(parts ...string) string {
rows := make([][]string, len(parts))
for i, p := range parts {
rows[i] = lines(p)
}
var out []string
for r := range rows[0] {
var b strings.Builder
for _, cols := range rows {
if r < len(cols) {
b.WriteString(cols[r])
}
}
out = append(out, b.String())
}
return strings.Join(out, "\n")
}