|
1 | 1 | <?php |
| 2 | +/** |
| 3 | + * Handles the `worktree` command and its subcommands. |
| 4 | + */ |
| 5 | + |
2 | 6 | namespace StellarWP\Slic; |
3 | 7 |
|
4 | 8 | // Load worktree utility functions |
5 | 9 | require_once __DIR__ . '/../worktree-utils.php'; |
6 | 10 |
|
| 11 | +if ( $is_help ) { |
| 12 | + $help = <<< HELP |
| 13 | + SUMMARY: |
| 14 | +
|
| 15 | + Manage git worktrees with dedicated slic stacks. |
| 16 | +
|
| 17 | + USAGE: |
| 18 | +
|
| 19 | + <yellow>{$cli_name} worktree <subcommand> [<args>]</yellow> |
| 20 | +
|
| 21 | + SUBCOMMANDS: |
| 22 | +
|
| 23 | + <light_cyan>add <branch> [-y|--yes]</light_cyan> |
| 24 | + Create a new git worktree for the specified branch with a dedicated slic stack. |
| 25 | +
|
| 26 | + <light_cyan>list</light_cyan> |
| 27 | + List all worktrees and their associated slic stacks. |
| 28 | +
|
| 29 | + <light_cyan>merge <branch> [-y|--yes]</light_cyan> |
| 30 | + Merge worktree branch into base branch and remove the worktree stack. |
| 31 | + Must be run from the base stack directory, not from within the worktree. |
| 32 | +
|
| 33 | + <light_cyan>remove <branch> [-y|--yes]</light_cyan> |
| 34 | + Remove a worktree and its associated slic stack. |
| 35 | +
|
| 36 | + <light_cyan>sync</light_cyan> |
| 37 | + Synchronize git worktrees with slic registry, removing stale entries. |
| 38 | +
|
| 39 | + OPTIONS: |
| 40 | +
|
| 41 | + <light_cyan>-y, --yes</light_cyan> |
| 42 | + Skip confirmation prompt and proceed immediately. Useful for non-interactive |
| 43 | + environments like CI pipelines and automation scripts. |
| 44 | +
|
| 45 | + EXAMPLES: |
| 46 | +
|
| 47 | + <light_cyan>{$cli_name} worktree add fix/issue-123</light_cyan> |
| 48 | + Create a worktree for branch 'fix/issue-123' with a dedicated stack. |
| 49 | +
|
| 50 | + <light_cyan>{$cli_name} worktree add feature/new-feature -y</light_cyan> |
| 51 | + Create a worktree without confirmation prompt. |
| 52 | +
|
| 53 | + <light_cyan>{$cli_name} worktree list</light_cyan> |
| 54 | + Show all worktrees and their stacks. |
| 55 | +
|
| 56 | + <light_cyan>{$cli_name} worktree remove fix/issue-123</light_cyan> |
| 57 | + Remove the worktree for branch 'fix/issue-123' and its stack. |
| 58 | +
|
| 59 | + <light_cyan>{$cli_name} worktree merge fix/issue-123</light_cyan> |
| 60 | + Merge branch 'fix/issue-123' into base branch and clean up (from base stack directory). |
| 61 | +
|
| 62 | + <light_cyan>{$cli_name} worktree merge fix/issue-123 -y</light_cyan> |
| 63 | + Merge without confirmation prompt. |
| 64 | +
|
| 65 | + <light_cyan>{$cli_name} worktree sync</light_cyan> |
| 66 | + Synchronize worktrees with slic registry. |
| 67 | +
|
| 68 | + NOTE: |
| 69 | +
|
| 70 | + slic provides minimal git worktree integration. Use 'git worktree' directly |
| 71 | + for advanced operations. |
| 72 | + HELP; |
| 73 | + |
| 74 | + echo colorize( $help ); |
| 75 | + return; |
| 76 | +} |
| 77 | + |
7 | 78 | $worktree_subcommands = [ |
8 | 79 | 'add' => 'Create a new git worktree with dedicated stack', |
9 | 80 | 'list' => 'List worktrees and their stacks', |
| 81 | + 'merge' => 'Merge worktree branch and remove stack', |
10 | 82 | 'remove' => 'Remove a worktree and its stack', |
11 | 83 | 'sync' => 'Synchronize git worktrees with slic registry', |
12 | 84 | ]; |
13 | 85 |
|
14 | 86 | // Parse subcommand from args |
15 | 87 | $sub_args = args( [ 'subcommand' ], $args( '...' ), 0 ); |
16 | | -$subcommand = $sub_args( 'subcommand', false ); |
| 88 | +$wt_subcommand = $sub_args( 'subcommand', false ); |
17 | 89 |
|
18 | | -if (empty($subcommand)) { |
| 90 | +if (empty($wt_subcommand)) { |
19 | 91 | echo "Git Worktree Support for slic\n\n"; |
20 | 92 | echo "Available commands:\n"; |
21 | 93 | foreach ($worktree_subcommands as $cmd => $desc) { |
22 | 94 | echo " slic worktree $cmd - $desc\n"; |
23 | 95 | } |
24 | 96 | echo "\nNote: slic provides minimal git worktree integration.\n"; |
25 | 97 | echo "Use 'git worktree' directly for advanced operations.\n"; |
| 98 | + echo "\nRun 'slic worktree help' for more information.\n"; |
26 | 99 | exit(0); |
27 | 100 | } |
28 | 101 |
|
29 | | -$subcommand_file = __DIR__ . '/worktree/' . $subcommand . '.php'; |
| 102 | +$subcommand_file = __DIR__ . '/worktree/' . $wt_subcommand . '.php'; |
30 | 103 |
|
31 | 104 | if (!file_exists($subcommand_file)) { |
32 | | - echo "Unknown worktree command: $subcommand\n"; |
| 105 | + echo "Unknown worktree command: $wt_subcommand\n"; |
33 | 106 | echo "Run 'slic worktree' to see available commands.\n"; |
34 | 107 | exit(1); |
35 | 108 | } |
|
0 commit comments