refactor(cleanup): use deleteBranch use case instead of hand-rolled ladder#20
Merged
Merged
Conversation
…adder PR #17 extracted the local branch-deletion policy (deleteBranch → BRANCH_NOT_MERGED fallback to deleteBranchForce) into a dedicated use case, but cleanup-worktrees.ts still carried a 4th copy of the same ladder that was missed during that refactor. Migrate that call site to deleteBranch({ branch, force: true, deleteRemote: false }) and map the typed outcome onto the existing cleanup reports: - deleted → cleaned / branch-only (unchanged) - failed → error with the git error message cleanup never touches the remote, so deleteRemote stays off; force=true mirrors the previous unconditional fallback, so observable behavior of wt cleanup is identical. Existing cleanup tests stay green. Added one new test exercising the failed-mapping branch.
Reviewers flagged that the `not-merged` outcome was silently treated as success (fell through to the `cleaned` / `branch-only` report) because `force: true` makes it statically unreachable today. That invariant lived only in the PR description. Replace the `if status === "failed"` check with an exhaustive `switch` on `outcome.status` so: - a future contract change in `deleteBranch` (new outcome, weakened force semantics) fails the typecheck instead of silently misreporting a non-deleted branch as `cleaned`; - the mapping (`deleted` / `failed` / `not-merged`) is documented in code, not only in the PR body. Observable behavior unchanged. Tests stay green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
deleteBranch→BRANCH_NOT_MERGED→deleteBranchForce) into a dedicated use case atsrc/application/use-cases/delete-branch.ts.cleanup-worktrees.tsstill carried a 4th copy of that ladder that was missed during the original refactor.deleteBranch({ branch, force: true, deleteRemote: false })and mapped the typed outcome onto the existing cleanup reports.Why
Single source of truth for the delete-branch policy — future tweaks (error-code semantics, force semantics, remote handling) now live in one place. Removes the last hand-rolled copy.
Mapping
deleted→ existingcleaned/branch-onlyreport (unchanged).failed→ existingerrorreport carrying the git error message.not-mergedis unreachable here because we passforce: true, mirroring the previous unconditional fallback.deleteRemote: false— cleanup never touches the remote in this code path.Behavior
Observable behavior of
wt cleanupis unchanged. All existing cleanup tests stay green without modification. Added one new test for thefailed-mapping branch (force fallback errors surface as anerrorreport).Closes Vikunja #46 (id 308)