feat(doctor): add town-git check for version control
Checks whether the town root (~/gt) is under git version control. Having the town harness in git is optional but recommended for: - Backing up personal Gas Town configuration and history - Tracking mail and coordination beads - Easier federation across machines 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
88
internal/doctor/town_git_check_test.go
Normal file
88
internal/doctor/town_git_check_test.go
Normal file
@@ -0,0 +1,88 @@
|
||||
package doctor
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewTownGitCheck(t *testing.T) {
|
||||
check := NewTownGitCheck()
|
||||
|
||||
if check.Name() != "town-git" {
|
||||
t.Errorf("expected name 'town-git', got %q", check.Name())
|
||||
}
|
||||
|
||||
if check.Description() == "" {
|
||||
t.Error("expected non-empty description")
|
||||
}
|
||||
|
||||
if check.CanFix() {
|
||||
t.Error("expected CanFix() to return false")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTownGitCheck_NoGitDir(t *testing.T) {
|
||||
// Create temp directory without .git
|
||||
tmpDir, err := os.MkdirTemp("", "town-git-test-*")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
ctx := &CheckContext{TownRoot: tmpDir}
|
||||
check := NewTownGitCheck()
|
||||
result := check.Run(ctx)
|
||||
|
||||
if result.Status != StatusWarning {
|
||||
t.Errorf("expected StatusWarning, got %v", result.Status)
|
||||
}
|
||||
|
||||
if result.FixHint == "" {
|
||||
t.Error("expected non-empty FixHint")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTownGitCheck_WithGitDir(t *testing.T) {
|
||||
// Create temp directory with .git
|
||||
tmpDir, err := os.MkdirTemp("", "town-git-test-*")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
gitDir := filepath.Join(tmpDir, ".git")
|
||||
if err := os.Mkdir(gitDir, 0755); err != nil {
|
||||
t.Fatalf("failed to create .git dir: %v", err)
|
||||
}
|
||||
|
||||
ctx := &CheckContext{TownRoot: tmpDir}
|
||||
check := NewTownGitCheck()
|
||||
result := check.Run(ctx)
|
||||
|
||||
if result.Status != StatusOK {
|
||||
t.Errorf("expected StatusOK, got %v", result.Status)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTownGitCheck_GitIsFile(t *testing.T) {
|
||||
// Create temp directory with .git as a file (worktree case)
|
||||
tmpDir, err := os.MkdirTemp("", "town-git-test-*")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
gitFile := filepath.Join(tmpDir, ".git")
|
||||
if err := os.WriteFile(gitFile, []byte("gitdir: /some/path"), 0644); err != nil {
|
||||
t.Fatalf("failed to create .git file: %v", err)
|
||||
}
|
||||
|
||||
ctx := &CheckContext{TownRoot: tmpDir}
|
||||
check := NewTownGitCheck()
|
||||
result := check.Run(ctx)
|
||||
|
||||
if result.Status != StatusWarning {
|
||||
t.Errorf("expected StatusWarning for .git file, got %v", result.Status)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user