Module: Ace::Git::Atoms::RepositoryStateDetector

Defined in:
lib/ace/git/atoms/repository_state_detector.rb

Overview

Detect repository state: clean, dirty, rebasing, merging Pure function that uses CommandExecutor for git commands

Class Method Summary collapse

Class Method Details

.clean?(executor: CommandExecutor) ⇒ Boolean

Check if repository is in a clean state

Parameters:

  • executor (Module) (defaults to: CommandExecutor)

    Command executor

Returns:

  • (Boolean)

    True if clean



31
32
33
# File 'lib/ace/git/atoms/repository_state_detector.rb', line 31

def clean?(executor: CommandExecutor)
  detect(executor: executor) == :clean
end

.detect(executor: CommandExecutor) ⇒ Symbol

Detect current repository state

Parameters:

  • executor (Module) (defaults to: CommandExecutor)

    Command executor (default: CommandExecutor)

Returns:

  • (Symbol)

    One of :clean, :dirty, :rebasing, :merging, :unknown



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ace/git/atoms/repository_state_detector.rb', line 13

def detect(executor: CommandExecutor)
  return :unknown unless executor.in_git_repo?

  # Check for rebase in progress
  return :rebasing if rebasing?(executor: executor)

  # Check for merge in progress
  return :merging if merging?(executor: executor)

  # Check for uncommitted changes
  return :dirty if dirty?(executor: executor)

  :clean
end

.dirty?(executor: CommandExecutor) ⇒ Boolean

Check if repository has uncommitted changes

Parameters:

  • executor (Module) (defaults to: CommandExecutor)

    Command executor

Returns:

  • (Boolean)

    True if dirty



38
39
40
41
42
43
44
# File 'lib/ace/git/atoms/repository_state_detector.rb', line 38

def dirty?(executor: CommandExecutor)
  # Check git status for changes
  result = executor.execute("git", "status", "--porcelain")
  return false unless result[:success]

  !result[:output].strip.empty?
end

.merging?(executor: CommandExecutor) ⇒ Boolean

Check if repository is in merge state

Parameters:

  • executor (Module) (defaults to: CommandExecutor)

    Command executor

Returns:

  • (Boolean)

    True if merging



62
63
64
65
66
67
68
69
# File 'lib/ace/git/atoms/repository_state_detector.rb', line 62

def merging?(executor: CommandExecutor)
  # Check for MERGE_HEAD file
  git_dir = executor.execute("git", "rev-parse", "--git-dir")
  return false unless git_dir[:success]

  git_path = git_dir[:output].strip
  File.exist?(File.join(git_path, "MERGE_HEAD"))
end

.rebasing?(executor: CommandExecutor) ⇒ Boolean

Check if repository is in rebase state

Parameters:

  • executor (Module) (defaults to: CommandExecutor)

    Command executor

Returns:

  • (Boolean)

    True if rebasing



49
50
51
52
53
54
55
56
57
# File 'lib/ace/git/atoms/repository_state_detector.rb', line 49

def rebasing?(executor: CommandExecutor)
  # Check for rebase-apply or rebase-merge directories
  git_dir = executor.execute("git", "rev-parse", "--git-dir")
  return false unless git_dir[:success]

  git_path = git_dir[:output].strip
  File.exist?(File.join(git_path, "rebase-apply")) ||
    File.exist?(File.join(git_path, "rebase-merge"))
end

.state_description(executor: CommandExecutor) ⇒ String

Get human-readable state description

Parameters:

  • executor (Module) (defaults to: CommandExecutor)

    Command executor

Returns:

  • (String)

    State description



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ace/git/atoms/repository_state_detector.rb', line 74

def state_description(executor: CommandExecutor)
  case detect(executor: executor)
  when :clean
    "clean (no uncommitted changes)"
  when :dirty
    "dirty (uncommitted changes)"
  when :rebasing
    "rebasing in progress"
  when :merging
    "merge in progress"
  else
    "unknown state"
  end
end