Sha256: 2d8cb9b047ff58d45186ce900be09f9af0c9011a0adbbb4e5f7aa386b84fbe1a

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

module Mercurial  
  class RepositoryNotFound < Error; end
  
  class Repository
    
    def self.create(destination)
      init_repository(destination)      
    end
    
    def self.open(destination)
      if File.exists?(destination)
        new(destination)
      else
        raise Mercurial::RepositoryNotFound.new(destination)
      end
    end
    
    def initialize(source)
      @path = source
    end
    
    def shell
      @_shell ||= Mercurial::Shell.new(self)
    end
    
    def config
      @_config ||= Mercurial::ConfigFile.new(self)
    end
    
    def hooks
      @_hook_factory ||= Mercurial::HookFactory.new(self)
    end
    
    def commits
      @_commits ||= Mercurial::CommitFactory.new(self)
    end
    
    def branches
      @_branches ||= Mercurial::BranchFactory.new(self)
    end
    
    def tags
      @_tags ||= Mercurial::TagFactory.new(self)
    end
    
    def diffs
      @_diffs ||= Mercurial::DiffFactory.new(self)
    end
    
    def nodes
      @_nodes ||= Mercurial::NodeFactory.new(self)
    end
    
    def manifest
      @_manifest ||= Mercurial::Manifest.new(self)
    end
    
    def file_index
      @_file_index ||= Mercurial::FileIndex.new(self)
    end
    
    def node(name, hash_id)
      nodes.find(name, hash_id)
    end
    
    def destroy!
      FileUtils.rm_rf(path)
    end
    
    def path
      File.expand_path(@path)
    end
    
    def dothg_path
      File.join(path, '.hg')
    end
    
    def mtime
      File.mtime(dothg_path).to_i
    end
    
  protected
  
    def self.init_repository(destination)
      Mercurial::Shell.run("mkdir -p #{ destination }")
      open(destination).tap do |repo|
        repo.shell.hg('init', :cache => false)
        repo.shell.hg('update null', :cache => false)
      end
    end
    
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mercurial-ruby-0.3.0 lib/mercurial-ruby/repository.rb