Repo

class
Superclass
Object
Included Modules
Hglib::VersionInfo
Extended With
Loggability

Attributes

path[R]

The path to the repository

Public Class Methods

anchor
new( path )

Create a new Repo object that will operate on the Mercurial repo at the specified path.

# File lib/hglib/repo.rb, line 28
def initialize( path )
        @path = Pathname( path )
        @server = nil
end

Public Instance Methods

anchor
add( *files, **options )

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.

# File lib/hglib/repo.rb, line 98
def add( *files, **options )
        self.server.run( :add, *files, **options )
        return true
end
anchor
add_remove( *files, **options )
Alias for: addremove
anchor
addr( *files, **options )
Alias for: addremove
anchor
addremove( *files, **options )

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.

# File lib/hglib/repo.rb, line 120
def addremove( *files, **options )
        self.server.run( :addremove, *files, **options )
        return true
end
Also aliased as: add_remove , addr
anchor
bookmark( *names, **options )

Create new bookmarks with the specified names.

# File lib/hglib/repo.rb, line 184
def bookmark( *names, **options )
        raise "expected at least one bookmark name" if names.empty?

        self.server.run( :bookmark, *names, **options )
        return true
end
anchor
bookmarks()

Return a Hglib::Repo::Bookmark object for each bookmark in the repo.

# File lib/hglib/repo.rb, line 193
def bookmarks
        options = { list: true }
        response = self.server.run_with_json_template( :bookmarks, **options )
        return response.map {|bk| Hglib::Repo::Bookmark.new(self, **bk) }
end
anchor
clean?()

Returns true if the repo has no outstanding changes.

# File lib/hglib/repo.rb, line 256
def clean?
        return !self.dirty?
end
anchor
commit( *files, **options )

Commit the specified files with the given options.

# File lib/hglib/repo.rb, line 129
def commit( *files, **options )
        self.server.run( :commit, *files, **options )
        return true
end
anchor
config( untrusted: false )

Fetch the current global Mercurial config and return it as an Hglib::Config object.

# File lib/hglib/repo.rb, line 202
def config( untrusted: false )
        options = { untrusted: untrusted }
        config = self.server.run_with_json_template( :showconfig, **options )
        return Hglib::Config.new( config )
end
anchor
diff( *files, **options )

Return a String showing differences between revisions for the specified files in the unified diff format.

# File lib/hglib/repo.rb, line 86
def diff( *files, **options )
        return self.server.run( :diff, *files, **options )
end
anchor
dirty?()

Returns true if the repo has outstanding changes.

# File lib/hglib/repo.rb, line 250
def dirty?
        return self.identify.dirty?
end
anchor
draft?( revset=nil )

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.

# File lib/hglib/repo.rb, line 270
def draft?( revset=nil )
        return self.phase( revset ).values.all?( :draft )
end
anchor
id( source=nil, **options )
Alias for: identity
anchor
identify( source=nil, **options )

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.

# File lib/hglib/repo.rb, line 63
def identify( source=nil, **options )
        response = self.server.run_with_json_template( :identify, source, **options )

        data = response.first
        return Hglib::Repo::Id.new( **data )
end
Also aliased as: identity
anchor
identity( source=nil, **options )
Also aliased as: id
Alias for: identify
anchor
log( *files, **options )

Return an Array of Hglib::Repo::LogEntry objects that describes the revision history of the specified files or the entire project.

# File lib/hglib/repo.rb, line 75
def log( *files, **options )
        options[:graph] = false

        entries = self.server.run_with_json_template( :log, *files, **options )

        return entries.map {|entry| Hglib::Repo::LogEntry.new(entry) }
end
anchor
paths()

Fetch a Hash of aliases for remote repositories.

# File lib/hglib/repo.rb, line 210
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
anchor
phase( revset=nil, **options )

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.

# File lib/hglib/repo.rb, line 232
def phase( revset=nil, **options )
        response = self.server.run( :phase, revset, **options )

        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
anchor
public?( revset=nil )

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.

# File lib/hglib/repo.rb, line 263
def public?( revset=nil )
        return self.phase( revset ).values.all?( :public )
end
anchor
pull( source=nil, **options )

Pull changes from the specified source (which defaults to the default path) into the local repository.

# File lib/hglib/repo.rb, line 137
def pull( source=nil, **options )
        self.server.run( :pull, source, **options )
        return true
end
anchor
pull_update( source=nil, **options )

Pull changes from the specified source into the local repository and update to the new branch head if new descendents were pulled.

# File lib/hglib/repo.rb, line 145
def pull_update( source=nil, **options )
        options[:update] = true
        return self.pull( source, **options )
end
anchor
push( destination=nil, **options )

Push changes to the specified destination.

# File lib/hglib/repo.rb, line 159
def push( destination=nil, **options )
        self.server.run( :push, destination, **options )
        return true
end
anchor
secret?( revset=nil )

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.

# File lib/hglib/repo.rb, line 277
def secret?( revset=nil )
        return self.phase( revset ).values.all?( :secret )
end
anchor
server()

Return the Hglib::Server started for this Repo, creating it if necessary.

# File lib/hglib/repo.rb, line 44
def server
        return @server ||= self.create_server
end
anchor
stat( *args, **options )
Alias for: status
anchor
status( *args, **options )

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.

# File lib/hglib/repo.rb, line 52
def status( *args, **options )
        response = self.server.run_with_json_template( :status, *args, **options )

        return response.map {|entry| Hglib::Repo::StatusEntry.new(entry) }
end
Also aliased as: stat
anchor
tag( *names, **options )

Name a revision using names.

# File lib/hglib/repo.rb, line 166
def tag( *names, **options )
        raise "expected at least one tag name" if names.empty?

        response = self.server.run( :tag, *names, **options )
        self.logger.debug "Got TAGS response: %p" % [ response ]

        return true
end
anchor
tags()

Return a Hglib::Repo::Tag object for each tag in the repo.

# File lib/hglib/repo.rb, line 177
def tags
        response = self.server.run_with_json_template( :tags )
        return response.flatten.map {|tag| Hglib::Repo::Tag.new(self, **tag) }
end
anchor
update( rev=nil, **options )

Update the working directory or switch revisions.

# File lib/hglib/repo.rb, line 152
def update( rev=nil, **options )
        self.server.run( :update, rev, **options )
        return true
end

Protected Instance Methods

anchor
create_server()

Create an Hglib::Server for this Repo.

# File lib/hglib/repo.rb, line 287
def create_server
        return Hglib::Server.new( self.path.to_s )
end
anchor
logger()

Return the logger for this object; aliased to avoid the conflict with `hg log`.

# File lib/hglib/repo.rb, line 293
def logger
        return Loggability[ self ]
end
anchor
truncate( string, maxlength=80 )

Return the given string with the middle truncated so that it's maxlength characters long if it exceeds that length.

# File lib/hglib/repo.rb, line 300
def truncate( string, maxlength=80 )
        return string if maxlength < 8
        return string if string.length - maxlength - 5 <= 0

        return string[0 .. (maxlength / 2) - 3 ] +
                ' ... ' +
                string[ -((maxlength / 2) -3) .. -1 ]
end