refactor: Add CleanupStatus type to replace raw strings (gt-77gq7)
Introduces a typed CleanupStatus with constants: - CleanupClean, CleanupUncommitted, CleanupStash, CleanupUnpushed, CleanupUnknown Adds helper methods: - IsSafe(): true for clean status - RequiresRecovery(): true for uncommitted/stash/unpushed - CanForceRemove(): true if force flag can bypass Updated files to use the new type: - internal/polecat/types.go: Type definition and methods - internal/polecat/manager.go: Validation logic - internal/witness/handlers.go: Nuke safety checks - internal/cmd/done.go: Status reporting - internal/cmd/polecat.go: Recovery status checks 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -78,3 +78,48 @@ func (p *Polecat) Summary() Summary {
|
||||
Issue: p.Issue,
|
||||
}
|
||||
}
|
||||
|
||||
// CleanupStatus represents the git state of a polecat for cleanup decisions.
|
||||
// The Witness uses this to determine whether it's safe to nuke a polecat worktree.
|
||||
type CleanupStatus string
|
||||
|
||||
const (
|
||||
// CleanupClean means the worktree has no uncommitted work and is safe to remove.
|
||||
CleanupClean CleanupStatus = "clean"
|
||||
|
||||
// CleanupUncommitted means there are uncommitted changes in the worktree.
|
||||
CleanupUncommitted CleanupStatus = "has_uncommitted"
|
||||
|
||||
// CleanupStash means there are stashed changes that would be lost.
|
||||
CleanupStash CleanupStatus = "has_stash"
|
||||
|
||||
// CleanupUnpushed means there are commits not pushed to the remote.
|
||||
CleanupUnpushed CleanupStatus = "has_unpushed"
|
||||
|
||||
// CleanupUnknown means the status could not be determined.
|
||||
CleanupUnknown CleanupStatus = "unknown"
|
||||
)
|
||||
|
||||
// IsSafe returns true if the status indicates it's safe to remove the worktree
|
||||
// without losing any work.
|
||||
func (s CleanupStatus) IsSafe() bool {
|
||||
return s == CleanupClean
|
||||
}
|
||||
|
||||
// RequiresRecovery returns true if the status indicates there is work that
|
||||
// needs to be recovered before removal. This includes uncommitted changes,
|
||||
// stashes, and unpushed commits.
|
||||
func (s CleanupStatus) RequiresRecovery() bool {
|
||||
switch s {
|
||||
case CleanupUncommitted, CleanupStash, CleanupUnpushed:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// CanForceRemove returns true if the status allows forced removal.
|
||||
// Uncommitted changes can be force-removed, but stashes and unpushed commits cannot.
|
||||
func (s CleanupStatus) CanForceRemove() bool {
|
||||
return s == CleanupClean || s == CleanupUncommitted
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user