| 409 | } |
| 410 | |
| 411 | func clean(configuration config.Configuration) { |
| 412 | git("fetch", configuration.RemoteName, "--prune") |
| 413 | |
| 414 | currentBranch := gitCurrentBranch() |
| 415 | localBranches := gitBranches() |
| 416 | |
| 417 | if currentBranch.isOrphanWipBranch(configuration) { |
| 418 | currentBaseBranch, _ := determineBranches(currentBranch, localBranches, configuration) |
| 419 | |
| 420 | say.Info("Current branch " + currentBranch.Name + " is an orphan") |
| 421 | if currentBaseBranch.exists(localBranches) { |
| 422 | git("checkout", currentBaseBranch.Name) |
| 423 | } else if newBranch("main").exists(localBranches) { |
| 424 | git("checkout", "main") |
| 425 | } else { |
| 426 | git("checkout", "master") |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | for _, branch := range localBranches { |
| 431 | b := newBranch(branch) |
| 432 | if b.isOrphanWipBranch(configuration) { |
| 433 | say.Info("Removing orphan wip branch " + b.Name) |
| 434 | git("branch", "-D", b.Name) |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | } |
| 439 | |
| 440 | func (branch Branch) isOrphanWipBranch(configuration config.Configuration) bool { |
| 441 | return branch.IsWipBranch(configuration) && !branch.hasRemoteBranch(configuration) |