Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions src/commands/worktree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,18 +754,11 @@ pub fn handle_remove(
no_delete_branch: bool,
force_delete: bool,
force_worktree: bool,
background: bool,
config: &WorktrunkConfig,
) -> anyhow::Result<RemoveResult> {
let repo = Repository::current();

// Show progress (unless running in background - output handler will show command)
if !background {
crate::output::print(progress_message(cformat!(
"Removing <bold>{worktree_name}</> worktree..."
)))?;
}

// Progress message is shown in handle_removed_worktree_output() after pre-remove hooks run
repo.prepare_worktree_removal(
RemoveTarget::Branch(worktree_name),
BranchDeletionMode::from_flags(no_delete_branch, force_delete),
Expand All @@ -782,16 +775,11 @@ pub fn handle_remove_current(
no_delete_branch: bool,
force_delete: bool,
force_worktree: bool,
background: bool,
config: &WorktrunkConfig,
) -> anyhow::Result<RemoveResult> {
let repo = Repository::current();

// Show progress (unless running in background - output handler will show command)
if !background {
crate::output::print(progress_message("Removing current worktree..."))?;
}

// Progress message is shown in handle_removed_worktree_output() after pre-remove hooks run
repo.prepare_worktree_removal(
RemoveTarget::Current,
BranchDeletionMode::from_flags(no_delete_branch, force_delete),
Expand Down
29 changes: 5 additions & 24 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1484,14 +1484,9 @@ fn main() {
if branches.is_empty() {
// No branches specified, remove current worktree
// Uses path-based removal to handle detached HEAD state
let result = handle_remove_current(
!delete_branch,
force_delete,
force,
background,
&config,
)
.context("Failed to remove worktree")?;
let result =
handle_remove_current(!delete_branch, force_delete, force, &config)
.context("Failed to remove worktree")?;
// Approval was handled at the gate
// Post-switch hooks are spawned internally by handle_remove_output
handle_remove_output(&result, background, verify)
Expand Down Expand Up @@ -1545,7 +1540,6 @@ fn main() {
!delete_branch,
force_delete,
force,
background,
&config,
) {
Ok(result) => {
Expand All @@ -1560,14 +1554,7 @@ fn main() {

// Handle branch-only cases (no worktree)
for branch in &branch_only {
match handle_remove(
branch,
!delete_branch,
force_delete,
force,
background,
&config,
) {
match handle_remove(branch, !delete_branch, force_delete, force, &config) {
Ok(result) => {
handle_remove_output(&result, background, verify)?;
}
Expand All @@ -1581,13 +1568,7 @@ fn main() {
// Remove current worktree last (if it was in the list)
// Post-switch hooks are spawned internally by handle_remove_output
if let Some((_path, _branch)) = current {
match handle_remove_current(
!delete_branch,
force_delete,
force,
background,
&config,
) {
match handle_remove_current(!delete_branch, force_delete, force, &config) {
Ok(result) => {
handle_remove_output(&result, background, verify)?;
}
Expand Down
9 changes: 9 additions & 0 deletions src/output/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,10 @@ fn handle_removed_worktree_output(
None,
)?;
} else {
// Progress message after pre-remove hooks, before actual removal
super::print(progress_message(
"Removing worktree (detached HEAD, no branch to delete)...",
))?;
let target_repo = worktrunk::git::Repository::at(worktree_path);
let _ = target_repo.run_command(&["fsmonitor--daemon", "stop"]);
if let Err(err) = repo.remove_worktree(worktree_path, force_worktree) {
Expand Down Expand Up @@ -742,6 +746,11 @@ fn handle_removed_worktree_output(
} else {
// Synchronous mode: remove immediately and report actual results

// Progress message after pre-remove hooks, before actual removal
super::print(progress_message(cformat!(
"Removing <bold>{branch_name}</> worktree..."
)))?;

// Stop fsmonitor daemon first (best effort - ignore errors)
// This prevents zombie daemons from accumulating when using builtin fsmonitor
let target_repo = worktrunk::git::Repository::at(worktree_path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ info:
env:
APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
COLUMNS: "150"
COLUMNS: "500"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
Expand All @@ -33,8 +33,8 @@ exit_code: 0
----- stdout -----

----- stderr -----
◎ Removing feature-hook worktree...
◎ Running pre-remove project hook @ _REPO_.feature-hook:
  echo 'About to remove worktree'
About to remove worktree
◎ Removing feature-hook worktree...
✓ Removed feature-hook worktree & branch (same commit as main, _)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ info:
env:
APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
COLUMNS: "150"
COLUMNS: "500"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
Expand All @@ -33,7 +33,6 @@ exit_code: 1
----- stdout -----

----- stderr -----
◎ Removing feature-fail worktree...
◎ Running pre-remove project hook @ _REPO_.feature-fail:
  exit 1
✗ pre-remove command failed: exit status: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ info:
env:
APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
COLUMNS: "150"
COLUMNS: "500"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
Expand All @@ -32,7 +32,7 @@ exit_code: 0
----- stdout -----

----- stderr -----
◎ Removing current worktree...
◎ Running pre-remove project hook:
  touch _REPO_/m.txt
✓ Removed worktree (detached HEAD, no branch to delete)
◎ Removing worktree (detached HEAD, no branch to delete)...
✓ Removed worktree (detached HEAD, no branch to delete)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ info:
env:
APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
COLUMNS: "150"
COLUMNS: "500"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
Expand All @@ -33,7 +33,6 @@ exit_code: 0
----- stdout -----

----- stderr -----
◎ Removing feature-templates worktree...
◎ Running pre-remove project:branch @ _REPO_.feature-templates:
  echo 'Branch: feature-templates'
Branch: feature-templates
Expand All @@ -43,4 +42,5 @@ exit_code: 0
◎ Running pre-remove project:worktree_name @ _REPO_.feature-templates:
  echo 'Name: repo.feature-templates'
Name: repo.feature-templates
◎ Removing feature-templates worktree...
✓ Removed feature-templates worktree & branch (same commit as main, _)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ info:
env:
APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
COLUMNS: "150"
COLUMNS: "500"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
Expand All @@ -32,5 +32,5 @@ exit_code: 0
----- stdout -----

----- stderr -----
◎ Removing current worktree...
◎ Removing worktree (detached HEAD, no branch to delete)...
✓ Removed worktree (detached HEAD, no branch to delete)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ info:
env:
APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
COLUMNS: "150"
COLUMNS: "500"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
Expand All @@ -32,7 +32,7 @@ exit_code: 0
----- stdout -----

----- stderr -----
◎ Removing current worktree...
◎ Removing feature worktree...
✓ Removed feature worktree & branch (same commit as main, _)
▲ Cannot change directory — shell integration not installed
↳ To enable automatic cd, run wt config shell install