Class: Ace::Git::Worktree::Commands::PruneCommand

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

Overview

Prune command

Cleans up git metadata for deleted worktrees and removes orphaned worktree directories that are no longer tracked by git.

Examples:

Prune deleted worktrees

PruneCommand.new.run([])

Prune with directory cleanup

PruneCommand.new.run(["--cleanup-directories"])

Instance Method Summary collapse

Constructor Details

#initializePruneCommand

Initialize a new PruneCommand



19
20
21
# File 'lib/ace/git/worktree/commands/prune_command.rb', line 19

def initialize
  @manager = Organisms::WorktreeManager.new
end

Instance Method Details

#run(args = []) ⇒ Integer

Run the prune command

Parameters:

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

    Command arguments

Returns:

  • (Integer)

    Exit code (0 for success, 1 for error)



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ace/git/worktree/commands/prune_command.rb', line 27

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

  validate_options(options)

  result = @manager.prune

  if result[:success]
    display_prune_result(result, options)

    # Additional directory cleanup if requested
    if options[:cleanup_directories]
      cleanup_orphaned_directories(options)
    end

    0
  else
    puts "Failed to prune worktrees: #{result[:error]}"
    1
  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 prune command

Returns:

  • (Integer)

    Exit code



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/prune_command.rb', line 61

def show_help
  puts <<~HELP
    ace-git-worktree prune - Clean up deleted worktrees

    USAGE:
        ace-git-worktree prune [OPTIONS]

    OPTIONS:
        --dry-run               Show what would be pruned without pruning
        --cleanup-directories   Remove orphaned worktree directories
        --verbose, -v           Show detailed pruning information
        --help, -h              Show this help message

    EXAMPLES:
        # Prune deleted worktrees (git metadata cleanup only)
        ace-git-worktree prune

        # Dry run to see what would be pruned
        ace-git-worktree prune --dry-run

        # Prune and cleanup orphaned directories
        ace-git-worktree prune --cleanup-directories

        # Verbose output
        ace-git-worktree prune --verbose

    WHAT IT DOES:
        1. Prunes git worktree metadata for deleted worktrees
        2. Removes stale worktree entries from git's tracking
        3. Optionally removes orphaned worktree directories
        4. Reports what was cleaned up

    SAFETY:
        • Only removes worktrees that are no longer tracked by git
        • Does not affect active worktrees or current worktree
        • Directory cleanup is optional and requires explicit flag
        • Dry run available to preview changes

    CONFIGURATION:
        Pruning behavior can be configured in .ace/git/worktree.yml:
        - cleanup.on_delete: Automatic cleanup on branch deletion
        - cleanup.on_merge: Automatic cleanup on branch merge
  HELP
  0
end