class Nucleon::Util::Git

Public Class Methods

load(path, options = {}) click to toggle source
   # File lib/core/util/git.rb
 9 def self.load(path, options = {})
10   epath   = File.expand_path(path)
11   git_dir = File.join(epath, '.git')
12   git     = nil
13   
14   begin
15     if File.exist?(git_dir)
16       if File.directory?(git_dir)
17         git = Rugged::Repository.new(git_dir)
18       else
19         # TODO: Find out if this is actually necessary with Rugged / LibGit2
20         git_dir = Util::Disk.read(git_dir)
21         unless git_dir.nil?
22           git_dir = git_dir.gsub(/^gitdir\:\s*/, '').strip
23         
24           if File.directory?(git_dir)
25             git         = Rugged::Repository.new(git_dir)
26             git.workdir = epath  
27           end
28         end
29       end      
30     elsif File.directory?(epath) && (options[:bare] || (epath =~ /\.git$/ && File.exist?(File.join(epath, 'HEAD'))))
31       git = Rugged::Repository.bare(epath)
32     end
33   rescue
34   end
35   
36   if git.nil? && options[:create]
37     FileUtils.mkdir_p(epath) unless File.directory?(epath)
38     if options[:bare]
39       git = Rugged::Repository.init_at(epath, :bare)
40     else
41       git = Rugged::Repository.init_at(epath)
42     end
43   end        
44   git
45 end