Class: Ace::Git::Worktree::Commands::RemoveCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/git/worktree/commands/remove_command.rb

Overview

Remove command

Removes worktrees with safety checks and cleanup options. Supports both task-aware and traditional worktree removal.

Examples:

Remove by task ID

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

Remove by branch name

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

Force remove

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

Instance Method Summary collapse

Constructor Details

#initializeRemoveCommand

Initialize a new RemoveCommand



24
25
26
27
# File 'lib/ace/git/worktree/commands/remove_command.rb', line 24

def initialize
  @manager = Organisms::WorktreeManager.new
  @task_fetcher = Molecules::TaskFetcher.new
end

Instance Method Details

#run(args = []) ⇒ Integer

Run the remove command

Parameters:

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

    Command arguments

Returns:

  • (Integer)

    Exit code (0 for success, 1 for error)



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ace/git/worktree/commands/remove_command.rb', line 33

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

  validate_options(options)

  if options[:task]
    remove_task_worktree(options)
  else
    remove_traditional_worktree(options)
  end
rescue ArgumentError => e
  puts "Error: #{e.message}"
  puts
  show_help
  1
rescue => e
  puts "Error: #{e.message}"
  1
end

#show_helpInteger

Show help for the remove command

Returns:

  • (Integer)

    Exit code



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
# File 'lib/ace/git/worktree/commands/remove_command.rb', line 57

def show_help
  puts <<~HELP
    ace-git-worktree remove - Remove a worktree

    USAGE:
        ace-git-worktree remove <identifier> [OPTIONS]
        ace-git-worktree remove --task <task-id> [OPTIONS]

    IDENTIFIERS:
        Task ID:                081, task.081, v.0.9.0+081
        Branch name:            feature-branch, main
        Directory name:        task.081, feature-branch
        Full path:              /path/to/worktree

    OPTIONS:
        --task <task-id>         Remove worktree for specific task
        --force                 Force removal even with uncommitted changes
        --keep-directory        Keep the worktree directory (default: remove)
        --delete-branch, -db    Also delete the associated branch
        --dry-run               Show what would be removed without removing
        --help, -h              Show this help message

    EXAMPLES:
        # Remove task worktree
        ace-git-worktree remove --task 081

        # Remove by branch name
        ace-git-worktree remove feature-branch

        # Force remove with changes
        ace-git-worktree remove --task 081 --force

        # Dry run to see what would be removed
        ace-git-worktree remove --task 081 --dry-run

        # Remove but keep directory
        ace-git-worktree remove --task 081 --keep-directory

    SAFETY:
        • The command checks for uncommitted changes
        • Use --force to remove worktrees with changes
        • Task removal also cleans up task metadata
        • Main worktree cannot be removed accidentally

    CONFIGURATION:
        Worktree removal respects settings in .ace/git/worktree.yml
  HELP
  0
end