Class: Ace::Git::Molecules::DiffGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/git/molecules/diff_generator.rb

Overview

Generate diffs using git commands with configuration options Migrated from ace-git-diff

Class Method Summary collapse

Class Method Details

.generate(config, executor: Atoms::CommandExecutor) ⇒ String

Generate diff based on configuration

Parameters:

  • config (Models::DiffConfig)

    Diff configuration

  • executor (Module) (defaults to: Atoms::CommandExecutor)

    Command executor (default: Atoms::CommandExecutor)

Returns:

  • (String)

    Raw diff output



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ace/git/molecules/diff_generator.rb', line 14

def generate(config, executor: Atoms::CommandExecutor)
  # Handle special cases first
  return executor.staged_diff if config.format == :staged
  return executor.working_diff if config.format == :working

  # Determine what to diff
  range = determine_range(config, executor)

  # Build git diff command
  cmd_parts = build_command(range, config)

  # Execute with configured timeout
  result = executor.execute(*cmd_parts, timeout: config.timeout)
  handle_result(result, cmd_parts)
end

.generate_for_range(range, config, executor: Atoms::CommandExecutor) ⇒ String

Generate diff for a specific range

Parameters:

  • range (String)

    Git range (e.g., “HEAD~5..HEAD”, “origin/main…HEAD”)

  • config (Models::DiffConfig)

    Configuration options

  • executor (Module) (defaults to: Atoms::CommandExecutor)

    Command executor

Returns:

  • (String)

    Diff output



47
48
49
50
51
# File 'lib/ace/git/molecules/diff_generator.rb', line 47

def generate_for_range(range, config, executor: Atoms::CommandExecutor)
  cmd_parts = build_command(range, config)
  result = executor.execute(*cmd_parts, timeout: config.timeout)
  handle_result(result, cmd_parts)
end

.generate_numstat(config, executor: Atoms::CommandExecutor) ⇒ String

Generate ‘git diff –numstat` output for structured file statistics. Uses the same range/path/flags logic as the main diff generation path.

Parameters:

  • config (Models::DiffConfig)

    Diff configuration

  • executor (Module) (defaults to: Atoms::CommandExecutor)

    Command executor (default: Atoms::CommandExecutor)

Returns:

  • (String)

    Numstat output



35
36
37
38
39
40
# File 'lib/ace/git/molecules/diff_generator.rb', line 35

def generate_numstat(config, executor: Atoms::CommandExecutor)
  range = determine_range(config, executor)
  cmd_parts = build_numstat_command(range, config)
  result = executor.execute(*cmd_parts, timeout: config.timeout)
  handle_result(result, cmd_parts)
end

.generate_since(since, config, executor: Atoms::CommandExecutor) ⇒ String

Generate diff since a date or commit

Parameters:

  • since (String)

    Date or commit reference

  • config (Models::DiffConfig)

    Configuration options

  • executor (Module) (defaults to: Atoms::CommandExecutor)

    Command executor

Returns:

  • (String)

    Diff output



58
59
60
61
62
63
64
# File 'lib/ace/git/molecules/diff_generator.rb', line 58

def generate_since(since, config, executor: Atoms::CommandExecutor)
  # Resolve since to commit
  since_ref = Atoms::DateResolver.resolve_since_to_commit(since, executor: executor)
  range = "#{since_ref}..HEAD"

  generate_for_range(range, config, executor: executor)
end

.staged(config, executor: Atoms::CommandExecutor) ⇒ String

Get staged diff with configuration

Parameters:

  • config (Models::DiffConfig)

    Configuration options

  • executor (Module) (defaults to: Atoms::CommandExecutor)

    Command executor

Returns:

  • (String)

    Staged diff output



70
71
72
73
74
# File 'lib/ace/git/molecules/diff_generator.rb', line 70

def staged(config, executor: Atoms::CommandExecutor)
  cmd_parts = build_command("--cached", config)
  result = executor.execute(*cmd_parts, timeout: config.timeout)
  handle_result(result, cmd_parts)
end

.working(config, executor: Atoms::CommandExecutor) ⇒ String

Get working directory diff with configuration

Parameters:

  • config (Models::DiffConfig)

    Configuration options

  • executor (Module) (defaults to: Atoms::CommandExecutor)

    Command executor

Returns:

  • (String)

    Working diff output



80
81
82
83
84
# File 'lib/ace/git/molecules/diff_generator.rb', line 80

def working(config, executor: Atoms::CommandExecutor)
  cmd_parts = build_command(nil, config)
  result = executor.execute(*cmd_parts, timeout: config.timeout)
  handle_result(result, cmd_parts)
end