Module: Hglib

Extended by:
VersionInfo, Loggability
Defined in:
lib/hglib.rb,
lib/hglib/mixins.rb

Overview

Toplevel namespace

Defined Under Namespace

Modules: Extension, Inspection, MethodUtilities, VersionInfo Classes: CommandError, Config, DisabledExtensionError, Error, Repo, Server

Constant Summary collapse

VERSION =

Package version

'0.11.0'
REVISION =

Version control revision

%q$Revision$
DEFAULT_HG_PATH =

The default path to the ‘hg` command

begin
	paths = ENV['PATH'].
		split( File::PATH_SEPARATOR ).
		map {|dir| Pathname(dir) + 'hg' }

	paths.find( &:executable? ) || Pathname( '/usr/bin/hg' )
end

Class Method Summary collapse

Methods included from VersionInfo

extension_enabled?, extension_versions, version, versions

Class Method Details

.clone(source_repo, local_dir = nil, **options) ⇒ Object

Clone the source_repo to the specified local_dir, which defaults to a directory with the basename of the source_repo in the current working directory.



176
177
178
179
180
181
182
# File 'lib/hglib.rb', line 176

def self::clone( source_repo, local_dir=nil, **options )
	output = self.server.run( :clone, source_repo, local_dir, **options )
	self.log.debug "Clone output: %s" % [ output ]

	local_dir ||= Pathname.pwd + File.basename( source_repo )
	return self.repo( local_dir )
end

.hg_pathObject

Return the currently-configured path to the ‘hg` binary./



124
125
126
# File 'lib/hglib.rb', line 124

def self::hg_path
	return @hg_path ||= DEFAULT_HG_PATH
end

.hg_path=(new_path) ⇒ Object

Set the path to the ‘hg` binary that will be used for any new commands.



130
131
132
# File 'lib/hglib.rb', line 130

def self::hg_path=( new_path )
	@hg_path = Pathname( new_path )
end

.init(dir, **options) ⇒ Object

Initialize a repository in the given dir and return a Hglib::Repo for it.



187
188
189
190
191
192
# File 'lib/hglib.rb', line 187

def self::init( dir, **options )
	output = self.server.run( :init, dir, **options )
	self.log.debug "Init output: %s" % [ output ]

	return self.repo( dir )
end

.is_repo?(dir) ⇒ Boolean

Returns true if the specified dir looks like it is a Mercurial repository.

Returns:

  • (Boolean)


160
161
162
163
164
# File 'lib/hglib.rb', line 160

def self::is_repo?( dir )
	dir = Pathname( dir )
	hgdir = dir + '.hg'
	return dir.directory? && hgdir.directory?
end

.repo(path = '.') ⇒ Object

Return an Hglib::Repo object for the specified path.



168
169
170
# File 'lib/hglib.rb', line 168

def self::repo( path='.' )
	return Hglib::Repo.new( path )
end

.reset_serverObject

Shut down and remove the ::server if one exists. Mostly used for testing.



150
151
152
153
154
155
# File 'lib/hglib.rb', line 150

def self::reset_server
	if ( server = @hg_server )
		@hg_server = nil
		server.stop
	end
end

.serverObject

Return an Hglib::Server started with no repository.



144
145
146
# File 'lib/hglib.rb', line 144

def self::server
	return @hg_server ||= Hglib::Server.new( nil )
end