Skip to content

refactor(cleanup): use deleteBranch use case instead of hand-rolled ladder#20

Merged
epodivilov merged 2 commits into
mainfrom
refactor/cleanup-use-delete-branch-use-case
Jun 20, 2026
Merged

refactor(cleanup): use deleteBranch use case instead of hand-rolled ladder#20
epodivilov merged 2 commits into
mainfrom
refactor/cleanup-use-delete-branch-use-case

Conversation

@epodivilov

Copy link
Copy Markdown
Owner

Summary

  • PR refactor(remove): extract branch-deletion policy into a use case #17 extracted the local branch-deletion policy (deleteBranchBRANCH_NOT_MERGEDdeleteBranchForce) into a dedicated use case at src/application/use-cases/delete-branch.ts.
  • cleanup-worktrees.ts still carried a 4th copy of that ladder that was missed during the original refactor.
  • Migrated that call site to 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 → existing cleaned / branch-only report (unchanged).
  • failed → existing error report carrying the git error message.
  • not-merged is unreachable here because we pass force: true, mirroring the previous unconditional fallback.
  • deleteRemote: false — cleanup never touches the remote in this code path.

Behavior

Observable behavior of wt cleanup is unchanged. All existing cleanup tests stay green without modification. Added one new test for the failed-mapping branch (force fallback errors surface as an error report).

Closes Vikunja #46 (id 308)

…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.
@epodivilov epodivilov merged commit 79cc733 into main Jun 20, 2026
1 check passed
@epodivilov epodivilov deleted the refactor/cleanup-use-delete-branch-use-case branch June 20, 2026 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant