plandex-ai/plandex · error

Error deleting branch:

Error message

Error deleting branch: 

What it means

DeleteBranchHandler runs repo.GitDeleteBranch(branch) inside a write-locked repo operation and returns HTTP 500 'Error deleting branch: <err>' if the git deletion fails. This surfaces raw git errors (ref not found, lock contention, repo corruption) from the plan's underlying git repository.

Source

Thrown at app/server/handlers/branches.go:202

	ctx, cancel := context.WithCancel(r.Context())

	err := db.ExecRepoOperation(db.ExecRepoOperationParams{
		OrgId:    auth.OrgId,
		UserId:   auth.User.Id,
		PlanId:   planId,
		Branch:   "main",
		Reason:   "delete branch",
		Scope:    db.LockScopeWrite,
		Ctx:      ctx,
		CancelFn: cancel,
	}, func(repo *db.GitRepo) error {
		err := repo.GitDeleteBranch(branch)
		return err
	})

	if err != nil {
		log.Printf("Error deleting branch: %v\n", err)
		http.Error(w, "Error deleting branch: "+err.Error(), http.StatusInternalServerError)
		return
	}

	log.Println("Successfully deleted branch")
}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Check the wrapped git error in the response/logs — 'not found' means the branch was already deleted and can be treated as success
  2. Remove stale .git lock files in the plan's repo if present
  3. Refresh the branch list and retry with an existing branch name
  4. Verify repo storage health (disk space, git fsck) if corruption is suspected

Example fix

// before
client.DeleteBranch(planId, "feature-x") // may 500 if already gone
// after
branches, _ := client.ListBranches(planId)
if contains(branches, "feature-x") {
    client.DeleteBranch(planId, "feature-x")
}
Defensive patterns

Strategy: validation

Validate before calling

// client: confirm branch still exists before deleting
branches, err := listBranches(planId)
if err != nil { return err }
if !slices.Contains(branches, branch) { return nil } // already gone — treat as success

Type guard

func branchExists(branches []Branch, name string) bool {
    for _, b := range branches { if b.Name == name { return true } }
    return false
}

Try / catch

// idempotent delete: tolerate 'not found' in the 500 body
if resp.StatusCode == http.StatusInternalServerError && strings.Contains(body, "not found") {
    return nil // already deleted
}

Prevention

When it happens

Trigger: DELETE of a non-main branch when: the branch ref does not exist in the git repo (already deleted, or exists only in the DB), git fails due to a stale index.lock, the repo directory is missing/corrupted, or the write lock times out / context is cancelled.

Common situations: Deleting a branch that was already removed by another user/session (double delete); DB and git state out of sync after a failed prior operation; crashed server leaving .git lock files; disk full on the plans volume.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/83290c0490a60375. Report an issue: GitHub.