Skip to content

fix(worktree): stale dir cleanup, random adjectives, and close hook fixes#62

Merged
neumie merged 3 commits intomainfrom
fix/worktree-stale-dir-and-random-adjectives
Mar 26, 2026
Merged

fix(worktree): stale dir cleanup, random adjectives, and close hook fixes#62
neumie merged 3 commits intomainfrom
fix/worktree-stale-dir-and-random-adjectives

Conversation

@neumie
Copy link
Copy Markdown
Contributor

@neumie neumie commented Mar 26, 2026

Summary

  • Fix worktree creation failing with "already exists" when a stale directory is left from a previous removal
  • Randomize adjective order in branch name generation so Phase 2 names don't always start with "velk"
  • Fix worktree close silently doing nothing when the before_remove hook terminal fails to spawn — now shows an error and aborts
  • Fix on_worktree_close hook running with a deleted CWD

Changes

Stale worktree directory cleanup (repository.rs)

  • Add clean_stale_worktree_dir() that checks git worktree list --porcelain to distinguish active worktrees from stale directories
  • Removes stale dirs and prunes metadata before git worktree add
  • Called from both create_worktree and create_worktree_with_start_point

Random adjective order (branch_names.rs)

  • Shuffle ADJECTIVE_STEMS indices alongside goods indices
  • Phase 2 and Phase 3 now pick a random adjective instead of always starting with "velk"

Close worktree hook fixes (close_worktree_dialog.rs, actions/project.rs)

  • When fire_before_worktree_remove_async returns empty results (hook terminal failed to create), show error and abort instead of silently closing the dialog with no removal
  • Move fire_on_worktree_close before git worktree remove in remove_worktree_project so the hook runs with a valid CWD

Test plan

  • Manually leave a stale directory at the expected worktree path, then create a worktree — should succeed
  • Create enough worktrees to exhaust plain names — adjective+good combos should use varied adjectives
  • Configure a before_remove hook, close a worktree — hook should complete before removal
  • Kill the shell before closing a worktree with before_remove hook — should show error, not silently skip
  • Configure an on_close hook, close a worktree — hook should run with valid CWD

@neumie neumie changed the title fix(git): clean stale worktree dirs and randomize adjective order fix(worktree): stale dir cleanup, random adjectives, and close hook fixes Mar 26, 2026
neumie and others added 3 commits March 26, 2026 17:15
Worktree creation failed with "already exists" when a stale directory
was left behind from a previous removal. Now both create_worktree and
create_worktree_with_start_point check for stale directories and clean
them up before running `git worktree add`.

Also shuffle ADJECTIVE_STEMS alongside goods so branch names in Phase 2
get a random adjective instead of always starting with "velk".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…to spawn

When `fire_before_worktree_remove_async` returned an empty vec (hook
terminal failed to create), no `PendingWorktreeClose` was registered and
the dialog closed silently — leaving the worktree stuck with no removal
ever happening. Now the code falls through to the immediate removal path
when the deferred hook fails to spawn.

Also move `fire_on_worktree_close` before `git worktree remove` in
`remove_worktree_project` so the hook runs with a valid CWD instead of
a deleted directory.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Show an error in the dialog instead of silently proceeding. The hook
is configured for a reason — if it can't run, the close should stop.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@neumie neumie force-pushed the fix/worktree-stale-dir-and-random-adjectives branch from bd727ff to 76e643d Compare March 26, 2026 16:17
@neumie neumie merged commit 7252e7d into main Mar 26, 2026
8 checks passed
@neumie neumie deleted the fix/worktree-stale-dir-and-random-adjectives branch March 26, 2026 16:48
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