Class: Ace::Git::Worktree::Commands::CleanupCommand

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

Overview

Cleanup command

Generates a complete, deterministic, report-only worktree cleanup inventory using ancestry as the first safe proof. No mutations are performed — this is strictly a report.

Examples:

Generate a cleanup report

CleanupCommand.new.run(["--target", "main", "--remote", "origin"])

JSON output for automation

CleanupCommand.new.run(["--target", "main", "--format", "json"])

Instance Method Summary collapse

Instance Method Details

#run(args = []) ⇒ Integer

Run the cleanup 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
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
# File 'lib/ace/git/worktree/commands/cleanup_command.rb', line 27

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

  validate_options(options)

  result = build_reporter(options).report

  if result[:success]
    if options[:apply]
      apply_result = apply_fresh_report(options)

      if apply_result[:success]
        # Strict rescan with the same selection
        final_result = build_reporter(options).report

        if final_result[:success]
          # Check require_only_target if needed
          if options[:require_only_target] && has_non_target_state?(final_result)
            puts "Cleanup applied successfully, but non-target state remains (failed strict --require-only-target check)."
            display_result(final_result, options)
            return 1
          end

          display_apply_result(apply_result, final_result, options)
          return 0
        else
          puts "Cleanup applied successfully, but final strict rescan failed: #{final_result[:error]}"
          return 1
        end
      else
        puts "Error applying cleanup: #{apply_result[:error]}"
        display_apply_result(apply_result, nil, options)
        return 1
      end
    else
      display_result(result, options)
      return 0
    end
  else
    if options[:format] == "json"
      puts JSON.pretty_generate(result)
    else
      puts "Error: #{result[:error]}"
    end
    1
  end
rescue ArgumentError => e
  puts "Error: #{e.message}"
  puts
  show_help
  1
rescue => e
  puts "Error: #{e.message}"
  1
end