Class: Hglib::Repo
- Inherits:
-
Object
- Object
- Hglib::Repo
- Extended by:
- Loggability
- Includes:
- VersionInfo
- Defined in:
- lib/hglib/repo.rb
Defined Under Namespace
Classes: Bookmark, Id, LogEntry, StatusEntry, Tag
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
The path to the repository.
Instance Method Summary collapse
-
#add(*files, **options) ⇒ Object
Schedule the given
filesto be version controlled and added to the repository on the next commit. -
#addremove(*files, **options) ⇒ Object
(also: #add_remove, #addr)
Add all new files and remove all missing files from the repository.
-
#bookmark(*names, **options) ⇒ Object
Create new bookmarks with the specified
names. -
#bookmarks ⇒ Object
Return a Hglib::Repo::Bookmark object for each bookmark in the repo.
-
#clean? ⇒ Boolean
Returns
trueif the repo has no outstanding changes. -
#commit(*files, **options) ⇒ Object
Commit the specified
fileswith the givenoptions. -
#config(untrusted: false) ⇒ Object
Fetch the current global Mercurial config and return it as an Hglib::Config object.
-
#diff(*files, **options) ⇒ Object
Return a String showing differences between revisions for the specified
filesin the unified diff format. -
#dirty? ⇒ Boolean
Returns
trueif the repo has outstanding changes. -
#draft?(revset = nil) ⇒ Boolean
Returns
trueif all of the changesets in the specifiedrevset(or the current changeset if norevsetis given) are in the draft phase. -
#identify(source = nil, **options) ⇒ Object
(also: #identity)
Return a Hglib::Repo::Id that identifies the repository state at the specified
revision, or the current revision if unspecified. -
#initialize(path) ⇒ Repo
constructor
Create a new Repo object that will operate on the Mercurial repo at the specified
path. -
#log(*files, **options) ⇒ Object
Return an Array of Hglib::Repo::LogEntry objects that describes the revision history of the specified
filesor the entire project. -
#paths ⇒ Object
Fetch a Hash of aliases for remote repositories.
-
#phase(revset = nil, **options) ⇒ Object
Set or show the current phase name for a
revset. -
#public?(revset = nil) ⇒ Boolean
Returns
trueif all of the changesets in the specifiedrevset(or the current changeset if norevsetis given) are in the public phase. -
#pull(source = nil, **options) ⇒ Object
Pull changes from the specified
source(which defaults to thedefaultpath) into the local repository. -
#pull_update(source = nil, **options) ⇒ Object
Pull changes from the specified
sourceinto the local repository and update to the new branch head if new descendents were pulled. -
#push(destination = nil, **options) ⇒ Object
Push changes to the specified
destination. -
#secret?(revset = nil) ⇒ Boolean
Returns
trueif all of the changesets in the specifiedrevset(or the current changeset if norevsetis given) are in the secret phase. -
#server ⇒ Object
Return the Hglib::Server started for this Repo, creating it if necessary.
-
#status(*args, **options) ⇒ Object
(also: #stat)
Return a Hash of the status of the files in the repo, keyed by Pathname of the file.
-
#tag(*names, **options) ⇒ Object
Name a revision using
names. -
#tags ⇒ Object
Return a Hglib::Repo::Tag object for each tag in the repo.
-
#update(rev = nil, **options) ⇒ Object
Update the working directory or switch revisions.
Methods included from VersionInfo
#extension_enabled?, #extension_versions, #version, #versions
Constructor Details
#initialize(path) ⇒ Repo
Create a new Repo object that will operate on the Mercurial repo at the specified path.
29 30 31 32 |
# File 'lib/hglib/repo.rb', line 29 def initialize( path ) @path = Pathname( path ) @server = nil end |
Instance Attribute Details
#path ⇒ Object (readonly)
The path to the repository
41 42 43 |
# File 'lib/hglib/repo.rb', line 41 def path @path end |
Instance Method Details
#add(*files, **options) ⇒ Object
Schedule the given files to be version controlled and added to the repository on the next commit. To undo an add before that, see #forget.
If no files are given, add all files to the repository (except files matching “.hgignore”).
Returns true if all files are successfully added.
99 100 101 102 |
# File 'lib/hglib/repo.rb', line 99 def add( *files, ** ) self.server.run( :add, *files, ** ) return true end |
#addremove(*files, **options) ⇒ Object Also known as: add_remove, addr
Add all new files and remove all missing files from the repository.
Unless files are given, new files are ignored if they match any of the patterns in “.hgignore”. As with #add, these changes take effect at the next commit.
Use the :similarity option to detect renamed files. This option takes a percentage between 0 (disabled) and 100 (files must be identical) as its value. With a value greater than 0, this compares every removed file with every added file and records those similar enough as renames. Detecting renamed files this way can be expensive. After using this option, you can call #status with the :copies options to check which files were identified as moved or renamed. If not specified, :similarity defaults to 100 and only renames of identical files are detected.
Returns true if all files are successfully added.
121 122 123 124 |
# File 'lib/hglib/repo.rb', line 121 def addremove( *files, ** ) self.server.run( :addremove, *files, ** ) return true end |
#bookmark(*names, **options) ⇒ Object
Create new bookmarks with the specified names.
185 186 187 188 189 190 |
# File 'lib/hglib/repo.rb', line 185 def bookmark( *names, ** ) raise "expected at least one bookmark name" if names.empty? self.server.run( :bookmark, *names, ** ) return true end |
#bookmarks ⇒ Object
Return a Hglib::Repo::Bookmark object for each bookmark in the repo.
194 195 196 197 198 |
# File 'lib/hglib/repo.rb', line 194 def bookmarks = { list: true } response = self.server.run_with_json_template( :bookmarks, ** ) return response.map {|bk| Hglib::Repo::Bookmark.new(self, **bk) } end |
#clean? ⇒ Boolean
Returns true if the repo has no outstanding changes.
257 258 259 |
# File 'lib/hglib/repo.rb', line 257 def clean? return !self.dirty? end |
#commit(*files, **options) ⇒ Object
Commit the specified files with the given options.
130 131 132 133 |
# File 'lib/hglib/repo.rb', line 130 def commit( *files, ** ) self.server.run( :commit, *files, ** ) return true end |
#config(untrusted: false) ⇒ Object
Fetch the current global Mercurial config and return it as an Hglib::Config object.
203 204 205 206 207 |
# File 'lib/hglib/repo.rb', line 203 def config( untrusted: false ) = { untrusted: untrusted } config = self.server.run_with_json_template( :showconfig, ** ) return Hglib::Config.new( config ) end |
#diff(*files, **options) ⇒ Object
Return a String showing differences between revisions for the specified files in the unified diff format.
87 88 89 |
# File 'lib/hglib/repo.rb', line 87 def diff( *files, ** ) return self.server.run( :diff, *files, ** ) end |
#dirty? ⇒ Boolean
Returns true if the repo has outstanding changes.
251 252 253 |
# File 'lib/hglib/repo.rb', line 251 def dirty? return self.identify.dirty? end |
#draft?(revset = nil) ⇒ Boolean
Returns true if all of the changesets in the specified revset (or the current changeset if no revset is given) are in the draft phase.
271 272 273 |
# File 'lib/hglib/repo.rb', line 271 def draft?( revset=nil ) return self.phase( revset ).values.all?( :draft ) end |
#identify(source = nil, **options) ⇒ Object Also known as: identity
Return a Hglib::Repo::Id that identifies the repository state at the specified revision, or the current revision if unspecified. A revision of ‘.` identifies the working directory parent without uncommitted changes.
64 65 66 67 68 69 |
# File 'lib/hglib/repo.rb', line 64 def identify( source=nil, ** ) response = self.server.run_with_json_template( :identify, source, ** ) data = response.first return Hglib::Repo::Id.new( **data ) end |
#log(*files, **options) ⇒ Object
Return an Array of Hglib::Repo::LogEntry objects that describes the revision history of the specified files or the entire project.
76 77 78 79 80 81 82 |
# File 'lib/hglib/repo.rb', line 76 def log( *files, ** ) [:graph] = false entries = self.server.run_with_json_template( :log, *files, ** ) return entries.map {|entry| Hglib::Repo::LogEntry.new(entry) } end |
#paths ⇒ Object
Fetch a Hash of aliases for remote repositories.
211 212 213 214 215 216 |
# File 'lib/hglib/repo.rb', line 211 def paths response = self.server.run_with_json_template( :paths ) return response.each_with_object({}) do |entry, hash| hash[ entry[:name].to_sym ] = URI( entry[:url] ) end end |
#phase(revset = nil, **options) ⇒ Object
Set or show the current phase name for a revset.
With no revset, operates on the current changeset.
You can set the phase of the specified revisions by passing one of the following options:
-
p: true / public: true
-
d: true / draft: true
-
s: true / secret: true
Returns a Hash of <local revision number> => <phase as a Symbol>. Setting the phase returns an empty Hash on success, and raises if there was a problem setting the phase.
233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/hglib/repo.rb', line 233 def phase( revset=nil, ** ) response = self.server.run( :phase, revset, ** ) return {} if response.empty? return response.lines.each_with_object({}) do |line, hash| m = line.match( /^(?<revnum>\d+): (?<phase>\w+)/ ) or raise "Couldn't parse phase response %p" % [ line ] hash[ m[:revnum].to_i ] = m[:phase].to_sym end end |
#public?(revset = nil) ⇒ Boolean
Returns true if all of the changesets in the specified revset (or the current changeset if no revset is given) are in the public phase.
264 265 266 |
# File 'lib/hglib/repo.rb', line 264 def public?( revset=nil ) return self.phase( revset ).values.all?( :public ) end |
#pull(source = nil, **options) ⇒ Object
Pull changes from the specified source (which defaults to the default path) into the local repository.
138 139 140 141 |
# File 'lib/hglib/repo.rb', line 138 def pull( source=nil, ** ) self.server.run( :pull, source, ** ) return true end |
#pull_update(source = nil, **options) ⇒ Object
Pull changes from the specified source into the local repository and update to the new branch head if new descendents were pulled.
146 147 148 149 |
# File 'lib/hglib/repo.rb', line 146 def pull_update( source=nil, ** ) [:update] = true return self.pull( source, ** ) end |
#push(destination = nil, **options) ⇒ Object
Push changes to the specified destination.
160 161 162 163 |
# File 'lib/hglib/repo.rb', line 160 def push( destination=nil, ** ) self.server.run( :push, destination, ** ) return true end |
#secret?(revset = nil) ⇒ Boolean
Returns true if all of the changesets in the specified revset (or the current changeset if no revset is given) are in the secret phase.
278 279 280 |
# File 'lib/hglib/repo.rb', line 278 def secret?( revset=nil ) return self.phase( revset ).values.all?( :secret ) end |
#server ⇒ Object
Return the Hglib::Server started for this Repo, creating it if necessary.
45 46 47 |
# File 'lib/hglib/repo.rb', line 45 def server return @server ||= self.create_server end |
#status(*args, **options) ⇒ Object Also known as: stat
Return a Hash of the status of the files in the repo, keyed by Pathname of the file. An empty Hash is returned if there are no files with one of the requested statuses.
53 54 55 56 57 |
# File 'lib/hglib/repo.rb', line 53 def status( *args, ** ) response = self.server.run_with_json_template( :status, *args, ** ) return response.map {|entry| Hglib::Repo::StatusEntry.new(entry) } end |
#tag(*names, **options) ⇒ Object
Name a revision using names.
167 168 169 170 171 172 173 174 |
# File 'lib/hglib/repo.rb', line 167 def tag( *names, ** ) raise "expected at least one tag name" if names.empty? response = self.server.run( :tag, *names, ** ) self.logger.debug "Got TAGS response: %p" % [ response ] return true end |
#tags ⇒ Object
Return a Hglib::Repo::Tag object for each tag in the repo.
178 179 180 181 |
# File 'lib/hglib/repo.rb', line 178 def response = self.server.run_with_json_template( :tags ) return response.flatten.map {|tag| Hglib::Repo::Tag.new(self, **tag) } end |
#update(rev = nil, **options) ⇒ Object
Update the working directory or switch revisions.
153 154 155 156 |
# File 'lib/hglib/repo.rb', line 153 def update( rev=nil, ** ) self.server.run( :update, rev, ** ) return true end |