class Mercurial::Repository

This class represents a Mercurial repository. Most of the time you will use this as a proxy for all your hg operations.

Public Class Methods

clone(url, destination, cmd_options) click to toggle source

Creates a clone of an existing repository via URL.

Example:

Mercurial::Repository.clone("file:///Users/ilya/Desktop/existing-repo", "/path/to/the/clone")
# File lib/mercurial-ruby/repository.rb, line 40
def self.clone(url, destination, cmd_options)
  create_destination(destination)
  opts = cmd_options.merge(:append_hg => true)
  Mercurial::Shell.run(["clone ? ?", url, destination], opts)
  open(destination)      
end
create(destination) click to toggle source

Creates a new repository on disk. Returns a {Mercurial::Repository Repository} instance.

Example:

Mercurial::Repository.create("/Users/ilya/Desktop/cool_repository")
# File lib/mercurial-ruby/repository.rb, line 16
def self.create(destination)
  init_repository(destination)      
end
new(source) click to toggle source
# File lib/mercurial-ruby/repository.rb, line 47
def initialize(source)
  @path = source
end
open(destination) click to toggle source

Opens an existing repository on disk. Returns a {Mercurial::Repository Repository} instance.

Example:

Mercurial::Repository.open("/Users/ilya/Desktop/existing-repo")
# File lib/mercurial-ruby/repository.rb, line 26
def self.open(destination)
  if File.exists?(destination)
    new(destination)
  else
    raise Mercurial::RepositoryNotFound.new(destination)
  end
end

Protected Class Methods

create_destination(path) click to toggle source
# File lib/mercurial-ruby/repository.rb, line 222
def self.create_destination(path)
  Mercurial::Shell.run("mkdir -p #{ path }")
end
init_repository(destination) click to toggle source
# File lib/mercurial-ruby/repository.rb, line 226
def self.init_repository(destination)
  create_destination(destination)
  open(destination).tap do |repo|
    repo.shell.hg('init', :cache => false)
    repo.shell.hg('update null', :cache => false)
  end
end

Public Instance Methods

blames() click to toggle source

Returns an instance of {Mercurial::BlameFactory BlameFactory} attached to the repository.

# File lib/mercurial-ruby/repository.rb, line 110
def blames
  @_blames ||= Mercurial::BlameFactory.new(self)
end
branches() click to toggle source

Returns an instance of {Mercurial::BranchFactory BranchFactory} attached to the repository.

# File lib/mercurial-ruby/repository.rb, line 82
def branches
  @_branches ||= Mercurial::BranchFactory.new(self)
end
cache_disabled_by_override?() click to toggle source
# File lib/mercurial-ruby/repository.rb, line 216
def cache_disabled_by_override?
  @cache_disabled_by_override || false
end
clone(destination_path, cmd_options={}) click to toggle source
# File lib/mercurial-ruby/repository.rb, line 135
def clone(destination_path, cmd_options={})
  self.class.clone(file_system_url, destination_path, cmd_options)
end
commits() click to toggle source

Returns an instance of {Mercurial::CommitFactory CommitFactory} attached to the repository.

# File lib/mercurial-ruby/repository.rb, line 75
def commits
  @_commits ||= Mercurial::CommitFactory.new(self)
end
config() click to toggle source

Returns an instance of {Mercurial::ConfigFile ConfigFile} attached to the repository.

# File lib/mercurial-ruby/repository.rb, line 61
def config
  @_config ||= Mercurial::ConfigFile.new(self)
end
destroy!() click to toggle source

Deletes the repository from disk.

# File lib/mercurial-ruby/repository.rb, line 174
def destroy!
  FileUtils.rm_rf(path)
end
diffs() click to toggle source

Returns an instance of {Mercurial::DiffFactory DiffFactory} attached to the repository.

# File lib/mercurial-ruby/repository.rb, line 96
def diffs
  @_diffs ||= Mercurial::DiffFactory.new(self)
end
dothg_path() click to toggle source
# File lib/mercurial-ruby/repository.rb, line 186
def dothg_path
  File.join(path, '.hg')
end
file_index() click to toggle source

Returns an instance of {Mercurial::FileIndex FileIndex} attached to the repository.

# File lib/mercurial-ruby/repository.rb, line 124
def file_index
  @_file_index ||= Mercurial::FileIndex.new(self)
end
file_system_url() click to toggle source
# File lib/mercurial-ruby/repository.rb, line 178
def file_system_url
  %Q[file://#{ path }]
end
hooks() click to toggle source

Returns an instance of {Mercurial::HookFactory HookFactory} attached to the repository.

# File lib/mercurial-ruby/repository.rb, line 68
def hooks
  @_hook_factory ||= Mercurial::HookFactory.new(self)
end
manifest() click to toggle source

Returns an instance of {Mercurial::Manifest Manifest} attached to the repository.

# File lib/mercurial-ruby/repository.rb, line 117
def manifest
  @_manifest ||= Mercurial::Manifest.new(self)
end
mtime() click to toggle source
# File lib/mercurial-ruby/repository.rb, line 190
def mtime
  File.mtime(dothg_path).to_i
end
no_cache() { || ... } click to toggle source

Accepts a block, executes all commands inside the block with caching disabled.

Example:

repository.no_cache do
  repository.commits.all
  repository.branches.all
end

Same as:

repository.commits.all :cache => false
repository.branches.all :cache => false
# File lib/mercurial-ruby/repository.rb, line 209
def no_cache
  @cache_disabled_by_override = true
  yield
ensure
  @cache_disabled_by_override = false
end
node(name, hash_id) click to toggle source

Shortcut for nodes.find.

# File lib/mercurial-ruby/repository.rb, line 131
def node(name, hash_id)
  nodes.find(name, hash_id)
end
nodes() click to toggle source

Returns an instance of {Mercurial::NodeFactory NodeFactory} attached to the repository.

# File lib/mercurial-ruby/repository.rb, line 103
def nodes
  @_nodes ||= Mercurial::NodeFactory.new(self)
end
path() click to toggle source
# File lib/mercurial-ruby/repository.rb, line 182
def path
  File.expand_path(@path)
end
paths() click to toggle source

Returns an array of repository's paths (as remotes).

# File lib/mercurial-ruby/repository.rb, line 162
def paths
  {}.tap do |result|
    shell.hg('paths').each_line do |line|
      path, url = *line.strip.split(" = ")
      result[path] = url
    end
  end
end
pull(origin='default', cmd_options={}) click to toggle source

Pull from an origin.

Example:

repository.pull
# File lib/mercurial-ruby/repository.rb, line 145
def pull(origin='default', cmd_options={})
  shell.hg(['pull ?', origin], cmd_options)
end
shell() click to toggle source

Returns an instance of {Mercurial::Shell Shell} attached to the repository.

# File lib/mercurial-ruby/repository.rb, line 54
def shell
  @_shell ||= Mercurial::Shell.new(self)
end
tags() click to toggle source

Returns an instance of {Mercurial::TagFactory TagFactory} attached to the repository.

# File lib/mercurial-ruby/repository.rb, line 89
def tags
  @_tags ||= Mercurial::TagFactory.new(self)
end
verify() click to toggle source

Run +hg verify+ on the repository. Returns true if verified, false otherwise.

# File lib/mercurial-ruby/repository.rb, line 152
def verify
  shell.hg('verify')
  true
rescue Mercurial::CommandError
  false
end