Class: Mercurial::Repository

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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, cmd_options)
  create_destination(destination)
  opts = cmd_options.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

#blamesObject

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

#branchesObject

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

Returns:

  • (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, cmd_options={})
  self.class.clone(file_system_url, destination_path, cmd_options)
end

#commitsObject

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

#configObject

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

#diffsObject

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_pathObject



186
187
188
# File 'lib/mercurial-ruby/repository.rb', line 186

def dothg_path
  File.join(path, '.hg')
end

#file_indexObject

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_urlObject



178
179
180
# File 'lib/mercurial-ruby/repository.rb', line 178

def file_system_url
  %Q[file://#{ path }]
end

#hooksObject

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

#manifestObject

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

#mtimeObject



190
191
192
# File 'lib/mercurial-ruby/repository.rb', line 190

def mtime
  File.mtime(dothg_path).to_i
end

#no_cacheObject

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

#nodesObject

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

#pathObject



182
183
184
# File 'lib/mercurial-ruby/repository.rb', line 182

def path
  File.expand_path(@path)
end

#pathsObject

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', cmd_options={})
  shell.hg(['pull ?', origin], cmd_options)
end

#shellObject

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

#tagsObject

Returns an instance of TagFactory attached to the repository.



89
90
91
# File 'lib/mercurial-ruby/repository.rb', line 89

def tags
  @_tags ||= Mercurial::TagFactory.new(self)
end

#verifyObject

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