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
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
# File lib/mercurial-ruby/repository.rb, line 47 def initialize(source) @path = source end
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
# File lib/mercurial-ruby/repository.rb, line 222 def self.create_destination(path) Mercurial::Shell.run("mkdir -p #{ path }") end
# 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
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
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
# File lib/mercurial-ruby/repository.rb, line 216 def cache_disabled_by_override? @cache_disabled_by_override || false end
# 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
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
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
Deletes the repository from disk.
# File lib/mercurial-ruby/repository.rb, line 174 def destroy! FileUtils.rm_rf(path) end
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
# File lib/mercurial-ruby/repository.rb, line 186 def dothg_path File.join(path, '.hg') end
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 lib/mercurial-ruby/repository.rb, line 178 def file_system_url %Q[file://#{ path }] end
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
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
# File lib/mercurial-ruby/repository.rb, line 190 def mtime File.mtime(dothg_path).to_i end
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
Shortcut for nodes.find
.
# File lib/mercurial-ruby/repository.rb, line 131 def node(name, hash_id) nodes.find(name, hash_id) end
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
# File lib/mercurial-ruby/repository.rb, line 182 def path File.expand_path(@path) end
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
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
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