Class: Ace::Git::Worktree::Commands::CreateCommand
- Inherits:
-
Object
- Object
- Ace::Git::Worktree::Commands::CreateCommand
- Defined in:
- lib/ace/git/worktree/commands/create_command.rb
Overview
Create command
Handles worktree creation with support for both task-aware and traditional worktree creation. Provides various options for customization.
Constant Summary collapse
- PR_NUMBER_PATTERN =
Pattern for validating PR numbers (digits only)
/^\d+$/
Instance Method Summary collapse
-
#initialize(manager: nil) ⇒ CreateCommand
constructor
Initialize a new CreateCommand.
-
#run(args = []) ⇒ Integer
Run the create command.
-
#show_help ⇒ Integer
Show help for the create command.
Constructor Details
#initialize(manager: nil) ⇒ CreateCommand
Initialize a new CreateCommand
27 28 29 |
# File 'lib/ace/git/worktree/commands/create_command.rb', line 27 def initialize(manager: nil) @manager = manager || Ace::Git::Worktree::Organisms::WorktreeManager.new end |
Instance Method Details
#run(args = []) ⇒ Integer
Run the create command
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ace/git/worktree/commands/create_command.rb', line 35 def run(args = []) # Show help if no arguments provided return show_help if args.empty? = parse_arguments(args) return show_help if [:help] () if [:task] create_task_worktree() elsif [:pr] create_pr_worktree() elsif [:branch] create_branch_worktree() else create_traditional_worktree() end rescue ArgumentError => e puts "Error: #{e.}" puts show_help 1 rescue Ace::Git::PrNotFoundError, Ace::Git::GhAuthenticationError, Ace::Git::GhNotInstalledError, Ace::Git::TimeoutError => e puts "Error: #{e.}" 1 rescue Ace::Git::Error => e # Catch other ace-git specific errors puts "Error: #{e.}" puts "Debug: #{e.class}" if ENV["DEBUG"] 1 end |
#show_help ⇒ Integer
Show help for the create command
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/ace/git/worktree/commands/create_command.rb', line 74 def show_help puts <<~HELP ace-git-worktree create - Create a new worktree USAGE: ace-git-worktree create <branch-name> [OPTIONS] ace-git-worktree create --task <task-id> [OPTIONS] ace-git-worktree create --pr <pr-number> [OPTIONS] ace-git-worktree create --branch <branch> [OPTIONS] TASK-AWARE CREATION: --task <task-id> Create worktree for a specific task Task ID formats: 081, task.081, v.0.9.0+081 PR-AWARE CREATION: --pr <number> Create worktree for a GitHub pull request --pull-request <number> (alias for --pr) Requires gh CLI to be installed and authenticated BRANCH-AWARE CREATION: -b <branch> Create worktree from a branch (local or remote) --branch <branch> (alias for -b) Remote branches: origin/feature, upstream/main Local branches: feature-name OPTIONS: --path <path> Custom worktree path (default: from config) --source <ref> Git ref to use as branch start-point (default: current branch) Examples: main, origin/develop, HEAD~3, commit-sha --dry-run Show what would be created without creating --no-status-update Skip marking task as in-progress (task mode only) --no-commit Skip committing task changes (task mode only) --no-push Skip pushing task changes to remote (task mode only) --no-upstream Skip pushing worktree branch with upstream tracking (task mode only) --no-pr Skip creating draft PR (task mode only) --push-remote <name> Remote to push to (default: origin) (task mode only) --no-auto-navigate Stay in current directory (default: navigate to worktree) --commit-message <msg> Custom commit message for task updates (task mode only) --force Create even if worktree already exists --help, -h Show this help message EXAMPLES: # Create task-aware worktree ace-git-worktree create --task 081 # Create task worktree based on main instead of current branch ace-git-worktree create --task 081 --source main # Create PR worktree ace-git-worktree create --pr 26 # Create worktree from remote branch ace-git-worktree create -b origin/feature/auth # Create worktree from local branch ace-git-worktree create -b my-feature # Create traditional worktree ace-git-worktree create feature-branch # Create traditional worktree based on specific commit ace-git-worktree create feature-branch --source HEAD~3 # Custom path and dry run ace-git-worktree create --pr 26 --path ~/worktrees --dry-run CONFIGURATION: Worktree creation is controlled by .ace/git/worktree.yml: - root_path: Default worktree root directory - task.auto_*: Automation settings for task workflows - pr.directory_format: PR worktree naming format (default: ace-pr-{number}) - pr.branch_format: PR branch naming format (default: pr-{number}-{slug}) Variables: {number}, {slug}, {title_slug}, {base_branch} - hooks.after_create: Commands to run after worktree creation REQUIREMENTS: PR-aware creation requires GitHub CLI (gh): - Install: brew install gh - Authenticate: gh auth login HELP 0 end |