Class: Git::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/coral_core/util/git/base.rb

Overview

******************************************************************************* Base Git definition

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base


Constructor / Destructor



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/coral_core/util/git/base.rb', line 18

def initialize(options = {})
  if working_dir = options[:working_directory]
    options[:repository] ||= File.join(working_dir, '.git')
    
    if File.file?(options[:repository])
      File.read(options[:repository]).each_line do |line|
        matches = line.match(/^\s*gitdir:\s*(.+)\s*/)
        if matches.length && matches[1]
          options[:repository] = matches[1]
          break
        end
      end        
    end
    
    if File.directory?(options[:repository])
      options[:index] ||= File.join(options[:repository], 'index')
    else
      raise GitDirectoryError.new("Git repository directory #{options[:repository]} not found for #{working_dir}")
    end
  end
  
  if options[:log]
    @logger = options[:log]
    @logger.info("Starting Git")
  else
    @logger = nil
  end
   
  @working_directory = options[:working_directory] ? Git::WorkingDirectory.new(options[:working_directory]) : nil
  @repository        = options[:repository] ? Git::Repository.new(options[:repository]) : nil 
  @index             = options[:index] ? Git::Index.new(options[:index], false) : nil
end

Instance Method Details

#add(path = '.', opts = {}) ⇒ Object


Commit extensions



54
55
56
# File 'lib/coral_core/util/git/base.rb', line 54

def add(path = '.', opts = {})
  self.lib.add(path, opts)
end

#pull(remote = 'origin', branch = 'master') ⇒ Object


Remote extensions



61
62
63
# File 'lib/coral_core/util/git/base.rb', line 61

def pull(remote = 'origin', branch = 'master')
  self.lib.pull(remote, branch)
end