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.1.16 lib/core/util/git.rb
nucleon-0.1.15 lib/core/util/git.rb
nucleon-0.1.14 lib/core/util/git.rb
nucleon-0.1.13 lib/core/util/git.rb
nucleon-0.1.12 lib/core/util/git.rb
nucleon-0.1.11 lib/core/util/git.rb
nucleon-0.1.10 lib/core/util/git.rb