Class: TestLauncher::Search::Git::Interface

Inherits:
Object
  • Object
show all
Defined in:
lib/test_launcher/search/git.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shell) ⇒ Interface

Returns a new instance of Interface.



12
13
14
# File 'lib/test_launcher/search/git.rb', line 12

def initialize(shell)
  @shell = shell
end

Instance Attribute Details

#shellObject (readonly)

Returns the value of attribute shell.



10
11
12
# File 'lib/test_launcher/search/git.rb', line 10

def shell
  @shell
end

Instance Method Details

#grep(regex, file_pattern) ⇒ Object



28
29
30
# File 'lib/test_launcher/search/git.rb', line 28

def grep(regex, file_pattern)
  shell.run("git grep --line-number --untracked --extended-regexp #{Shellwords.escape(regex)} -- '#{file_pattern}'")
end

#ls_files(pattern) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/test_launcher/search/git.rb', line 16

def ls_files(pattern)
  # files in the repo and unstaged files in the status
  shell.run("git ls-files '*#{pattern}*'") +
    shell
      .run("git status --porcelain=v2")
      .map { |l|
        type, path = l.split(" ")
        matcher = ".*#{pattern}.*".gsub("**", "*")
        path if type == "?" && path.match(%r{#{matcher}})              }
      .compact
end

#root_pathObject



32
33
34
35
36
37
38
# File 'lib/test_launcher/search/git.rb', line 32

def root_path
  shell.run("git rev-parse --show-toplevel").first.tap do
    if $? != 0
      raise NotInRepoError, "test_launcher must be used in a git repository"
    end
  end
end