Module: GitSupport

Included in:
GitFeeder, GitWorkingDirFeeder
Defined in:
lib/ruby_diff/git_support.rb

Overview

Common feeder support for working with git repositories.

Instance Method Summary collapse

Instance Method Details

#git(command) ⇒ Object

issues a command to git



26
27
28
29
30
31
32
# File 'lib/ruby_diff/git_support.rb', line 26

def git command
  output = `git #{command} 2>&1`.chomp
  unless $?.success?
    raise RuntimeError, output
  end
  output
end

#init_git(path, search_path = '') ⇒ Object

Finds root of a git repository. If the repository is the parent of the supplied path, then the remainder is made into the search path.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ruby_diff/git_support.rb', line 6

def init_git(path, search_path='')
  path = File.expand_path(path)
  if File.exist?(File.join(path, ".git"))
    # If this is the git repository
    @working_dir = path
    @search_path = search_path
    
  else
    next_search = File.join( File.basename(path), search_path )
    next_path = File.dirname(path)
    
    if next_path == path # We have reached the root, and can go no further
      raise "Could not find a git working directory"
    else
      init_git(next_path, next_search)
    end
  end
end