Skip to content

Commit 409e919

Browse files
committed
fix(doctor): detect missing trunk branch
The parent existence check was skipping trunk, so a deleted or renamed trunk branch wouldn't be reported. Now checks g.BranchExists(trunk) when the parent is trunk.
1 parent c4e7b75 commit 409e919

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

cmd/doctor.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,12 @@ func checkBranch(g *git.Git, cfg *config.Config, s *style.Style, branch string,
120120
}
121121

122122
trunk, _ := cfg.GetTrunk() //nolint:errcheck // already validated in runDoctor
123-
if parent != trunk && !g.BranchExists(parent) {
123+
if parent == trunk {
124+
if !g.BranchExists(trunk) {
125+
result.issues = append(result.issues, s.Errorf("Trunk branch %s does not exist locally", trunk))
126+
return result
127+
}
128+
} else if !g.BranchExists(parent) {
124129
result.issues = append(result.issues, s.Errorf("Parent branch %s does not exist locally", parent))
125130
return result
126131
}

e2e/doctor_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,22 @@ func TestDoctorFixUpdatesConfig(t *testing.T) {
150150
}
151151
}
152152

153+
func TestDoctorMissingTrunk(t *testing.T) {
154+
env := NewTestEnv(t)
155+
156+
env.MustRun("init")
157+
env.MustRun("create", "feature-a")
158+
env.CreateCommit("work on a")
159+
160+
// Delete the trunk branch (main) while on feature-a
161+
env.Git("branch", "-D", "main")
162+
163+
result := env.Run("doctor")
164+
if !result.ContainsStdout("Trunk branch") || !result.ContainsStdout("does not exist locally") {
165+
t.Errorf("expected missing trunk report, got: %s", result.Stdout)
166+
}
167+
}
168+
153169
func TestDoctorNotInitialized(t *testing.T) {
154170
env := NewTestEnv(t)
155171

0 commit comments

Comments
 (0)