Skip to content

Commit 964b27f

Browse files
authored
feat(workspace): accept repo@branch handle in worktree remove (#746)
`workspace worktree remove` only accepted the two-arg `<repo> <branch>` form and rejected the `<repo>@<branch-slug>` 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 `<repo>@<branch-slug>` 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
1 parent d644e17 commit 964b27f

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

inc/Cli/Commands/WorkspaceCommand.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3459,11 +3459,13 @@ private function renderGitOperationResult( string $operation, array $result, arr
34593459
* # Just dirty detection, skip size scan
34603460
* wp datamachine-code workspace worktree list --with-status
34613461
*
3462-
* # Remove a worktree
3462+
* # Remove a worktree (two-arg form, or a single <repo>@<branch-slug> handle)
34633463
* wp datamachine-code workspace worktree remove data-machine fix/foo
3464+
* wp datamachine-code workspace worktree remove data-machine@fix-foo
34643465
*
34653466
* # Force-remove a dirty worktree
34663467
* wp datamachine-code workspace worktree remove data-machine fix/foo --force
3468+
* wp datamachine-code workspace worktree remove data-machine@fix-foo --force
34673469
*
34683470
* # Prune stale worktree registry entries across all primaries
34693471
* wp datamachine-code workspace worktree prune
@@ -3746,12 +3748,22 @@ public function worktree( array $args, array $assoc_args ): void {
37463748
break;
37473749

37483750
case 'remove':
3749-
if ( empty($args[1]) || empty($args[2]) ) {
3750-
WP_CLI::error('Usage: worktree remove <repo> <branch> [--force]');
3751+
// Accept either the two-arg `<repo> <branch>` form or a single
3752+
// `<repo>@<branch-slug>` handle (as printed by `list`/`path`/cleanup
3753+
// output). When both positionals are present, the two-arg form wins and
3754+
// acts as the disambiguator; a lone first arg containing `@` is split on
3755+
// the FIRST `@` into repo + branch-slug.
3756+
$remove_repo = (string) ( $args[1] ?? '' );
3757+
$remove_branch = (string) ( $args[2] ?? '' );
3758+
if ( '' === $remove_branch && false !== strpos($remove_repo, '@') ) {
3759+
list( $remove_repo, $remove_branch ) = explode('@', $remove_repo, 2);
3760+
}
3761+
if ( '' === $remove_repo || '' === $remove_branch ) {
3762+
WP_CLI::error('Usage: worktree remove <repo> <branch> | <repo>@<branch-slug> [--force]');
37513763
return;
37523764
}
3753-
$input['repo'] = $args[1];
3754-
$input['branch'] = $args[2];
3765+
$input['repo'] = $remove_repo;
3766+
$input['branch'] = $remove_branch;
37553767
$input['force'] = ! empty($assoc_args['force']);
37563768
break;
37573769

0 commit comments

Comments
 (0)