Module: Ace::Git::Atoms::GitScopeFilter

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

Overview

Filters files by git status (staged, tracked, changed) Consolidated from ace-search GitScopeFilter (adapted to use CommandExecutor)

Class Method Summary collapse

Class Method Details

.get_changed_files(executor: CommandExecutor) ⇒ Array<String>

Get changed files (modified, not staged)

Parameters:

  • executor (Module) (defaults to: CommandExecutor)

    Command executor

Returns:

  • (Array<String>)

    List of changed file paths



50
51
52
53
54
55
# File 'lib/ace/git/atoms/git_scope_filter.rb', line 50

def get_changed_files(executor: CommandExecutor)
  result = executor.execute("git", "diff", "--name-only")
  return [] unless result[:success]

  result[:output].lines.map(&:strip).reject(&:empty?)
end

.get_files(scope, executor: CommandExecutor) ⇒ Array<String>

Get files based on git scope

Parameters:

  • scope (Symbol)

    :staged, :tracked, or :changed

  • executor (Module) (defaults to: CommandExecutor)

    Command executor (default: CommandExecutor)

Returns:

  • (Array<String>)

    List of file paths



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

def get_files(scope, executor: CommandExecutor)
  case scope
  when :staged
    get_staged_files(executor: executor)
  when :tracked
    get_tracked_files(executor: executor)
  when :changed
    get_changed_files(executor: executor)
  else
    []
  end
end

.get_files_between(from_ref, to_ref = "HEAD", executor: CommandExecutor) ⇒ Array<String>

Get files changed between two refs

Parameters:

  • from_ref (String)

    Start reference (e.g., “origin/main”)

  • to_ref (String) (defaults to: "HEAD")

    End reference (default: “HEAD”)

  • executor (Module) (defaults to: CommandExecutor)

    Command executor

Returns:

  • (Array<String>)

    List of changed file paths



76
77
78
79
80
81
# File 'lib/ace/git/atoms/git_scope_filter.rb', line 76

def get_files_between(from_ref, to_ref = "HEAD", executor: CommandExecutor)
  result = executor.execute("git", "diff", "--name-only", "#{from_ref}...#{to_ref}")
  return [] unless result[:success]

  result[:output].lines.map(&:strip).reject(&:empty?)
end

.get_staged_files(executor: CommandExecutor) ⇒ Array<String>

Get staged files

Parameters:

  • executor (Module) (defaults to: CommandExecutor)

    Command executor

Returns:

  • (Array<String>)

    List of staged file paths



30
31
32
33
34
35
# File 'lib/ace/git/atoms/git_scope_filter.rb', line 30

def get_staged_files(executor: CommandExecutor)
  result = executor.execute("git", "diff", "--cached", "--name-only")
  return [] unless result[:success]

  result[:output].lines.map(&:strip).reject(&:empty?)
end

.get_tracked_files(executor: CommandExecutor) ⇒ Array<String>

Get tracked files

Parameters:

  • executor (Module) (defaults to: CommandExecutor)

    Command executor

Returns:

  • (Array<String>)

    List of tracked file paths



40
41
42
43
44
45
# File 'lib/ace/git/atoms/git_scope_filter.rb', line 40

def get_tracked_files(executor: CommandExecutor)
  result = executor.execute("git", "ls-files")
  return [] unless result[:success]

  result[:output].lines.map(&:strip).reject(&:empty?)
end

.get_uncommitted_files(executor: CommandExecutor) ⇒ Array<String>

Get both staged and changed files (all uncommitted)

Parameters:

  • executor (Module) (defaults to: CommandExecutor)

    Command executor

Returns:

  • (Array<String>)

    List of all uncommitted file paths



60
61
62
# File 'lib/ace/git/atoms/git_scope_filter.rb', line 60

def get_uncommitted_files(executor: CommandExecutor)
  (get_staged_files(executor: executor) + get_changed_files(executor: executor)).uniq
end

.in_git_repo?(executor: CommandExecutor) ⇒ Boolean

Check if in git repository

Parameters:

  • executor (Module) (defaults to: CommandExecutor)

    Command executor

Returns:

  • (Boolean)

    True if in git repository



67
68
69
# File 'lib/ace/git/atoms/git_scope_filter.rb', line 67

def in_git_repo?(executor: CommandExecutor)
  executor.in_git_repo?
end