--- a/rakelib/hglib.rb Fri Aug 11 09:23:06 2017 +0200
+++ b/rakelib/hglib.rb Fri Aug 11 09:59:28 2017 +0200
@@ -103,21 +103,22 @@
gsub(/username\\=\S+/, "username\\=***").
gsub(/password\\=\S+/, "password\\=***")
$LOGGER.debug("executing: #{cmd_info}")
- puts cmd_info if defined? RakeFileUtils
+ if defined? RakeFileUtils and RakeFileUtils.verbose; puts cmd_info; end
+
if block_given?
stdout, stderr, status = Open3.capture3(*cmd)
case block.arity
- when 1
- STDOUT.print stdout
- STDERR.print stderr
- yield status
- when 2
- STDERR.print stderr
- yield status, stdout
- when 3
- yield status, stdout, stderr
- else
- raise Exception.new('invalid arity of given block')
+ when 1
+ STDOUT.print stdout
+ STDERR.print stderr
+ yield status
+ when 2
+ STDERR.print stderr
+ yield status, stdout
+ when 3
+ yield status, stdout, stderr
+ else
+ raise Exception.new("invalid arity of given block")
end
else
raise Exception.new("command failed: #{cmd.join(' ')}") unless system(*cmd)
@@ -241,7 +242,7 @@
# This may cause problems when using over VPN that assigns private address
# (the usuall case). In that case this code will treat is a local
# which may result in transfer of uncompressed data over WAN. Not nice,
- # This should be fixed, somehow.
+ # This should be fixed, somehow.
def self.host_on_lan?(hostname)
unless @@HOSTS_ON_LAN.has_key? hostname
require 'resolv'
@@ -340,7 +341,7 @@
log
end
- # Return changeset IDs of all head revisions.
+ # Return changeset IDs of all head revisions.
# If `branch` is given, return only heads in given
# branch.
def heads(branch = nil)
@@ -427,7 +428,8 @@
end
end
- def outgoing(remote = 'default', user: nil, pass: nil, rev: nil)
+ def outgoing(remote = 'default', user: nil, pass: nil, rev: nil, &block)
+ if !block_given?
hg('outgoing', remote, ssh: sshconf(remote), config: authconf(remote, user, pass), rev: rev) do |status, stdout|
case status.exitstatus
when 0
@@ -438,6 +440,9 @@
raise Exception.new("Failed to do 'outgoing' from #{remote} (exit code #{status.exitstatus})")
end
end
+ else
+ hg('outgoing', remote, ssh: sshconf(remote), config: authconf(remote, user, pass), rev: rev, &block)
+ end
end
def push(remote = 'default', user: nil, pass: nil, rev: nil, bookmarks: [])
@@ -470,7 +475,7 @@
#
# hg update
#
- # would do.
+ # would do.
def update(rev = nil)
if rev
raise Exception.new("Revision #{rev} does not exist") unless has_revision? rev
@@ -508,8 +513,14 @@
repo_dir_parent = File.dirname(repo_dir)
repo_dir_parent == repo_dir ? (repo_dir = nil) : (repo_dir = repo_dir_parent)
end
+ end
+
+ # Initializes and empty Mercurial repository in given `directory`
+ def self.init(directory)
+ FileUtils.mkdir_p File.dirname(directory)
+ HG::hg("init", directory)
+ return Repository.new(directory)
end
-
end # class Repository
# Return `true` if given `directory` is a root of mercurial
@@ -530,6 +541,6 @@
forest(path, &block)
end
end
- end
+ end
end
end # module HG