A Go CLI extension (gh stack) for managing stacked branches and pull requests. Uses Cobra for commands, bubbletea/lipgloss for TUI, and stretchr/testify for tests.
go mod download # install deps
go build -o gh-stack . # build
go vet ./... # static analysis. Always run before tests.
go test -race -count=1 ./... # tests with race detectionNo Makefile, no code generation, no external linter config. Standard Go toolchain only.
cmd/: One Cobra command per file. Each exports<Name>Cmd(cfg *config.Config)with logic inrun<Name>().internal/git/:Opsinterface (52 methods) wrapping git CLI.MockOpsfor tests. Package-level functions delegate to swappableopsvariable.internal/github/:ClientOpsinterface (13 methods) for GitHub API.MockClientfor tests. Stack operations use the public Stacks REST API (/repos/{owner}/{repo}/stacks).internal/config/:Configstruct passed to all commands. Holds I/O, colors, and test hooks (SelectFn,ConfirmFn,InputFn,GitHubClientOverride).internal/stack/: Stack file (.git/gh-stack, JSON) management with file locking.internal/tui/: bubbletea views (stackview,modifyview).
- Return typed
ExitErrorsentinels (codes 1-10 incmd/utils.go) fromRunE. Never callos.Exit()directly. - Check errors with
var exitErr *ExitError; errors.As(err, &exitErr). - Table-driven tests with
t.Run()subtests. - Use
config.NewTestConfig()for test configs with captured I/O. - Mock git:
restore := git.SetOps(&git.MockOps{...}); defer restore(). Always defer restore. - Mock GitHub:
cfg.GitHubClientOverride = &github.MockClient{...}. - Mock prompts: set
cfg.SelectFn,cfg.ConfirmFn, orcfg.InputFn. - Load stack files with
stack.Load(dir)after writing to get correct checksums.
For full architecture details, see AGENTS.md in the repository root.