Class: Mercurial::Repository
- Inherits:
-
Object
- Object
- Mercurial::Repository
- Defined in:
- lib/mercurial-ruby/repository.rb
Overview
This class represents a Mercurial repository. Most of the time you will use this as a proxy for all your hg operations.
Class Method Summary collapse
-
.clone(url, destination, cmd_options) ⇒ Object
Creates a clone of an existing repository via URL.
-
.create(destination) ⇒ Object
Creates a new repository on disk.
-
.open(destination) ⇒ Object
Opens an existing repository on disk.
Instance Method Summary collapse
-
#blames ⇒ Object
Returns an instance of BlameFactory attached to the repository.
-
#branches ⇒ Object
Returns an instance of BranchFactory attached to the repository.
- #cache_disabled_by_override? ⇒ Boolean
- #clone(destination_path, cmd_options = {}) ⇒ Object
-
#commits ⇒ Object
Returns an instance of CommitFactory attached to the repository.
-
#config ⇒ Object
Returns an instance of ConfigFile attached to the repository.
-
#destroy! ⇒ Object
Deletes the repository from disk.
-
#diffs ⇒ Object
Returns an instance of DiffFactory attached to the repository.
- #dothg_path ⇒ Object
-
#file_index ⇒ Object
Returns an instance of FileIndex attached to the repository.
- #file_system_url ⇒ Object
-
#hooks ⇒ Object
Returns an instance of HookFactory attached to the repository.
-
#initialize(source) ⇒ Repository
constructor
A new instance of Repository.
-
#manifest ⇒ Object
Returns an instance of Manifest attached to the repository.
- #mtime ⇒ Object
-
#no_cache ⇒ Object
Accepts a block, executes all commands inside the block with caching disabled.
-
#node(name, hash_id) ⇒ Object
Shortcut for
nodes.find
. -
#nodes ⇒ Object
Returns an instance of NodeFactory attached to the repository.
- #path ⇒ Object
-
#paths ⇒ Object
Returns an array of repository’s paths (as remotes).
-
#pull(origin = 'default', cmd_options = {}) ⇒ Object
Pull from an origin.
-
#shell ⇒ Object
Returns an instance of Shell attached to the repository.
-
#tags ⇒ Object
Returns an instance of TagFactory attached to the repository.
-
#verify ⇒ Object
Run hg verify on the repository.
Constructor Details
#initialize(source) ⇒ Repository
Returns a new instance of Repository.
47 48 49 |
# File 'lib/mercurial-ruby/repository.rb', line 47 def initialize(source) @path = source end |
Class Method Details
.clone(url, destination, cmd_options) ⇒ Object
Creates a clone of an existing repository via URL.
Example:
Mercurial::Repository.clone("file:///Users/ilya/Desktop/existing-repo", "/path/to/the/clone")
40 41 42 43 44 45 |
# File 'lib/mercurial-ruby/repository.rb', line 40 def self.clone(url, destination, ) create_destination(destination) opts = .merge(:append_hg => true) Mercurial::Shell.run(["clone ? ?", url, destination], opts) open(destination) end |
.create(destination) ⇒ Object
Creates a new repository on disk. Returns a Repository instance.
Example:
Mercurial::Repository.create("/Users/ilya/Desktop/cool_repository")
16 17 18 |
# File 'lib/mercurial-ruby/repository.rb', line 16 def self.create(destination) init_repository(destination) end |
.open(destination) ⇒ Object
Opens an existing repository on disk. Returns a Repository instance.
Example:
Mercurial::Repository.open("/Users/ilya/Desktop/existing-repo")
26 27 28 29 30 31 32 |
# 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 |
Instance Method Details
#blames ⇒ Object
Returns an instance of BlameFactory attached to the repository.
110 111 112 |
# File 'lib/mercurial-ruby/repository.rb', line 110 def blames @_blames ||= Mercurial::BlameFactory.new(self) end |
#branches ⇒ Object
Returns an instance of BranchFactory attached to the repository.
82 83 84 |
# File 'lib/mercurial-ruby/repository.rb', line 82 def branches @_branches ||= Mercurial::BranchFactory.new(self) end |
#cache_disabled_by_override? ⇒ Boolean
216 217 218 |
# File 'lib/mercurial-ruby/repository.rb', line 216 def cache_disabled_by_override? @cache_disabled_by_override || false end |
#clone(destination_path, cmd_options = {}) ⇒ Object
135 136 137 |
# File 'lib/mercurial-ruby/repository.rb', line 135 def clone(destination_path, ={}) self.class.clone(file_system_url, destination_path, ) end |
#commits ⇒ Object
Returns an instance of CommitFactory attached to the repository.
75 76 77 |
# File 'lib/mercurial-ruby/repository.rb', line 75 def commits @_commits ||= Mercurial::CommitFactory.new(self) end |
#config ⇒ Object
Returns an instance of ConfigFile attached to the repository.
61 62 63 |
# File 'lib/mercurial-ruby/repository.rb', line 61 def config @_config ||= Mercurial::ConfigFile.new(self) end |
#destroy! ⇒ Object
Deletes the repository from disk.
174 175 176 |
# File 'lib/mercurial-ruby/repository.rb', line 174 def destroy! FileUtils.rm_rf(path) end |
#diffs ⇒ Object
Returns an instance of DiffFactory attached to the repository.
96 97 98 |
# File 'lib/mercurial-ruby/repository.rb', line 96 def diffs @_diffs ||= Mercurial::DiffFactory.new(self) end |
#dothg_path ⇒ Object
186 187 188 |
# File 'lib/mercurial-ruby/repository.rb', line 186 def dothg_path File.join(path, '.hg') end |
#file_index ⇒ Object
Returns an instance of FileIndex attached to the repository.
124 125 126 |
# File 'lib/mercurial-ruby/repository.rb', line 124 def file_index @_file_index ||= Mercurial::FileIndex.new(self) end |
#file_system_url ⇒ Object
178 179 180 |
# File 'lib/mercurial-ruby/repository.rb', line 178 def file_system_url %Q[file://#{ path }] end |
#hooks ⇒ Object
Returns an instance of HookFactory attached to the repository.
68 69 70 |
# File 'lib/mercurial-ruby/repository.rb', line 68 def hooks @_hook_factory ||= Mercurial::HookFactory.new(self) end |
#manifest ⇒ Object
Returns an instance of Manifest attached to the repository.
117 118 119 |
# File 'lib/mercurial-ruby/repository.rb', line 117 def manifest @_manifest ||= Mercurial::Manifest.new(self) end |
#mtime ⇒ Object
190 191 192 |
# File 'lib/mercurial-ruby/repository.rb', line 190 def mtime File.mtime(dothg_path).to_i end |
#no_cache ⇒ Object
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
209 210 211 212 213 214 |
# 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) ⇒ Object
Shortcut for nodes.find
.
131 132 133 |
# File 'lib/mercurial-ruby/repository.rb', line 131 def node(name, hash_id) nodes.find(name, hash_id) end |
#nodes ⇒ Object
Returns an instance of NodeFactory attached to the repository.
103 104 105 |
# File 'lib/mercurial-ruby/repository.rb', line 103 def nodes @_nodes ||= Mercurial::NodeFactory.new(self) end |
#path ⇒ Object
182 183 184 |
# File 'lib/mercurial-ruby/repository.rb', line 182 def path File.(@path) end |
#paths ⇒ Object
Returns an array of repository’s paths (as remotes).
162 163 164 165 166 167 168 169 |
# 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 = {}) ⇒ Object
Pull from an origin.
Example:
repository.pull
145 146 147 |
# File 'lib/mercurial-ruby/repository.rb', line 145 def pull(origin='default', ={}) shell.hg(['pull ?', origin], ) end |
#shell ⇒ Object
Returns an instance of Shell attached to the repository.
54 55 56 |
# File 'lib/mercurial-ruby/repository.rb', line 54 def shell @_shell ||= Mercurial::Shell.new(self) end |
#tags ⇒ Object
Returns an instance of TagFactory attached to the repository.
89 90 91 |
# File 'lib/mercurial-ruby/repository.rb', line 89 def @_tags ||= Mercurial::TagFactory.new(self) end |
#verify ⇒ Object
Run hg verify on the repository. Returns true
if verified, false
otherwise.
152 153 154 155 156 157 |
# File 'lib/mercurial-ruby/repository.rb', line 152 def verify shell.hg('verify') true rescue Mercurial::CommandError false end |