Class: Ace::Git::Worktree::Commands::CreateCommand

Inherits:
Object
  • Object
show all
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.

Examples:

Task-aware worktree creation

CreateCommand.new.run(["--task", "081"])

Traditional worktree creation

CreateCommand.new.run(["feature-branch"])

Dry run

CreateCommand.new.run(["--task", "081", "--dry-run"])

Constant Summary collapse

PR_NUMBER_PATTERN =

Pattern for validating PR numbers (digits only)

/^\d+$/

Instance Method Summary collapse

Constructor Details

#initialize(manager: nil) ⇒ CreateCommand

Initialize a new CreateCommand

Parameters:

  • manager (Object) (defaults to: nil)

    Optional manager dependency for testing



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

Parameters:

  • args (Array<String>) (defaults to: [])

    Command arguments

Returns:

  • (Integer)

    Exit code (0 for success, 1 for error)



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?

  options = parse_arguments(args)
  return show_help if options[:help]

  validate_options(options)

  if options[:task]
    create_task_worktree(options)
  elsif options[:pr]
    create_pr_worktree(options)
  elsif options[:branch]
    create_branch_worktree(options)
  else
    create_traditional_worktree(options)
  end
rescue ArgumentError => e
  puts "Error: #{e.message}"
  puts
  show_help
  1
rescue Ace::Git::PrNotFoundError,
  Ace::Git::GhAuthenticationError,
  Ace::Git::GhNotInstalledError,
  Ace::Git::TimeoutError => e
  puts "Error: #{e.message}"
  1
rescue Ace::Git::Error => e
  # Catch other ace-git specific errors
  puts "Error: #{e.message}"
  puts "Debug: #{e.class}" if ENV["DEBUG"]
  1
end

#show_helpInteger

Show help for the create command

Returns:

  • (Integer)

    Exit code



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