Sha256: 33d76a96fc2092f63c7b76a7621031f0a9cf38a1e763b61e17ed80d9e418522b

Contents?: true

Size: 1.28 KB

Versions: 27

Compression:

Stored size: 1.28 KB

Contents

module Nucleon
module Util
class Git

  #-----------------------------------------------------------------------------
  # Git repo loader
  
  def self.load(path, options = {})
    epath   = File.expand_path(path)
    git_dir = File.join(epath, '.git')
    git     = nil
    
    begin
      if File.exist?(git_dir)
        if File.directory?(git_dir)
          git = Rugged::Repository.new(git_dir)
        else
          # TODO: Find out if this is actually necessary with Rugged / LibGit2
          git_dir = Util::Disk.read(git_dir)
          unless git_dir.nil?
            git_dir = git_dir.gsub(/^gitdir\:\s*/, '').strip
          
            if File.directory?(git_dir)
              git         = Rugged::Repository.new(git_dir)
              git.workdir = epath  
            end
          end
        end      
      elsif File.directory?(epath) && (options[:bare] || (epath =~ /\.git$/ && File.exist?(File.join(epath, 'HEAD'))))
        git = Rugged::Repository.bare(epath)
      end
    rescue
    end
    
    if git.nil? && options[:create]
      FileUtils.mkdir_p(epath) unless File.directory?(epath)
      if options[:bare]
        git = Rugged::Repository.init_at(epath, :bare)
      else
        git = Rugged::Repository.init_at(epath)
      end
    end        
    git
  end
end
end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
nucleon-0.2.16 lib/core/util/git.rb
nucleon-0.2.15 lib/core/util/git.rb
nucleon-0.2.14 lib/core/util/git.rb
nucleon-0.2.13 lib/core/util/git.rb
nucleon-0.2.12 lib/core/util/git.rb
nucleon-0.2.11 lib/core/util/git.rb
nucleon-0.2.10 lib/core/util/git.rb
nucleon-0.2.9 lib/core/util/git.rb
nucleon-0.2.8 lib/core/util/git.rb
nucleon-0.2.7 lib/core/util/git.rb
nucleon-0.2.6 lib/core/util/git.rb
nucleon-0.2.5 lib/core/util/git.rb
nucleon-0.2.4 lib/core/util/git.rb
nucleon-0.2.3 lib/core/util/git.rb
nucleon-0.2.2 lib/core/util/git.rb
nucleon-0.2.1 lib/core/util/git.rb
nucleon-0.2.0 lib/core/util/git.rb
nucleon-0.1.19 lib/core/util/git.rb
nucleon-0.1.18 lib/core/util/git.rb
nucleon-0.1.17 lib/core/util/git.rb