From 9d2ed8c06e0925a596c00d6479c299c49ea8c3ec Mon Sep 17 00:00:00 2001 From: Chris Huber Date: Tue, 16 Jun 2026 02:04:32 +0000 Subject: [PATCH] feat(workspace): accept repo@branch handle in worktree remove `workspace worktree remove` only accepted the two-arg ` ` form and rejected the `@` handle that the rest of the workspace surface (list/show/path/finalize/cleanup output) prints and accepts. Copying a handle from `list`/cleanup output and pasting it into `remove` failed every time. Accept a single `@` handle as the first positional in addition to the existing two-arg form. When both positionals are present the two-arg form wins as the disambiguator; a lone first arg containing `@` is split on the first `@`. The underlying ability already slugifies the branch, so passing the slug half is safe and idempotent. Closes #745 --- inc/Cli/Commands/WorkspaceCommand.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/inc/Cli/Commands/WorkspaceCommand.php b/inc/Cli/Commands/WorkspaceCommand.php index cc070be..fdd5ebe 100644 --- a/inc/Cli/Commands/WorkspaceCommand.php +++ b/inc/Cli/Commands/WorkspaceCommand.php @@ -3459,11 +3459,13 @@ private function renderGitOperationResult( string $operation, array $result, arr * # Just dirty detection, skip size scan * wp datamachine-code workspace worktree list --with-status * - * # Remove a worktree + * # Remove a worktree (two-arg form, or a single @ handle) * wp datamachine-code workspace worktree remove data-machine fix/foo + * wp datamachine-code workspace worktree remove data-machine@fix-foo * * # Force-remove a dirty worktree * wp datamachine-code workspace worktree remove data-machine fix/foo --force + * wp datamachine-code workspace worktree remove data-machine@fix-foo --force * * # Prune stale worktree registry entries across all primaries * wp datamachine-code workspace worktree prune @@ -3746,12 +3748,22 @@ public function worktree( array $args, array $assoc_args ): void { break; case 'remove': - if ( empty($args[1]) || empty($args[2]) ) { - WP_CLI::error('Usage: worktree remove [--force]'); + // Accept either the two-arg ` ` form or a single + // `@` handle (as printed by `list`/`path`/cleanup + // output). When both positionals are present, the two-arg form wins and + // acts as the disambiguator; a lone first arg containing `@` is split on + // the FIRST `@` into repo + branch-slug. + $remove_repo = (string) ( $args[1] ?? '' ); + $remove_branch = (string) ( $args[2] ?? '' ); + if ( '' === $remove_branch && false !== strpos($remove_repo, '@') ) { + list( $remove_repo, $remove_branch ) = explode('@', $remove_repo, 2); + } + if ( '' === $remove_repo || '' === $remove_branch ) { + WP_CLI::error('Usage: worktree remove | @ [--force]'); return; } - $input['repo'] = $args[1]; - $input['branch'] = $args[2]; + $input['repo'] = $remove_repo; + $input['branch'] = $remove_branch; $input['force'] = ! empty($assoc_args['force']); break;