mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Add SCM module for Mercurial from Matthew Elder (closes #4150)
git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@4830 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
fd2b1cc00b
commit
1a39079947
3 changed files with 87 additions and 1 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Add SCM module for Mercurial (closes #4150) [Matthew Elder]
|
||||
|
||||
* Remove unused line in SCM::Base (closes #5619) [chris@seagul.co.uk]
|
||||
|
||||
* More efficient "svn log" usage (closes #5620) [Anatol Pomozov]
|
||||
|
|
3
THANKS
3
THANKS
|
@ -1,3 +1,4 @@
|
|||
* Bazaar (v1) SCM Module: Edd Dumbill <edd@usefulinc.com>
|
||||
* Perforce SCM Module: Richard McMahon <richie.mcmahon@gmail.com>
|
||||
* Bazaar-NG SCM Module: Damien Merenne <dam@capsule.org>
|
||||
* Bazaar-NG SCM Module: Damien Merenne <dam@capsule.org>
|
||||
* Mercurial SCM Module: Matthew Elder <mae@mindflowsolutions.com>
|
||||
|
|
83
lib/capistrano/scm/mercurial.rb
Normal file
83
lib/capistrano/scm/mercurial.rb
Normal file
|
@ -0,0 +1,83 @@
|
|||
require 'capistrano/scm/base'
|
||||
|
||||
module Capistrano
|
||||
module SCM
|
||||
|
||||
# An SCM module for using Mercurial as your source control tool.
|
||||
# You can use it by placing the following line in your configuration:
|
||||
#
|
||||
# set :scm, :mercurial
|
||||
#
|
||||
# Also, this module accepts a <tt>:mercurial</tt> configuration variable,
|
||||
# which (if specified) will be used as the full path to the hg
|
||||
# executable on the remote machine:
|
||||
#
|
||||
# set :mercurial, "/usr/local/bin/hg"
|
||||
class Mercurial < Base
|
||||
# Return a string identifying the tip changeset in the mercurial
|
||||
# repository. Note that this fetches the tip changeset from the
|
||||
# local repository, but capistrano will deploy from your _remote_
|
||||
# repository. So just make sure your local repository is synchronized
|
||||
# with your remote one.
|
||||
def latest_revision
|
||||
`#{mercurial} tip --template '{node|short}'`
|
||||
end
|
||||
|
||||
# Return the changeset currently deployed.
|
||||
def current_revision(actor)
|
||||
# NOTE:
|
||||
# copied almost verbatim from svn except its not cast into an int
|
||||
# this should be the same for almost _every_ scm can we take it out
|
||||
# of SCM-specific code?
|
||||
latest = actor.releases.last
|
||||
grep = %(grep " #{latest}$" #{configuration.deploy_to}/revisions.log)
|
||||
result = ""
|
||||
actor.run(grep, :once => true) do |ch, str, out|
|
||||
result << out if str == :out
|
||||
raise "could not determine current changeset" if str == :err
|
||||
end
|
||||
|
||||
date, time, user, changeset, dir = result.split
|
||||
raise "current changeset not found in revisions.log" unless dir == latest
|
||||
changeset
|
||||
end
|
||||
|
||||
# Return a string containing the diff between the two changesets. +from+
|
||||
# and +to+ may be in any format that mercurial recognizes as a valid
|
||||
# changeset. If +from+ is +nil+, it defaults to the last deployed
|
||||
# changeset. If +to+ is +nil+, it defaults to the current working
|
||||
# directory.
|
||||
def diff(actor, from = current_revision(actor), to = nil)
|
||||
cmd = "#{mercurial} diff -r #{from}"
|
||||
cmd << " -r #{to}" if to
|
||||
`#{cmd}`
|
||||
end
|
||||
|
||||
# Check out (on all servers associated with the current task) the latest
|
||||
# revision. Uses the given actor instance to execute the command. If
|
||||
# mercurial asks for a password this will automatically provide it
|
||||
# (assuming the requested password is the same as the password for
|
||||
# logging into the remote server.) If ssh repository method is used,
|
||||
# authorized keys must be setup.
|
||||
def checkout(actor)
|
||||
command = "#{mercurial} clone -U #{configuration.repository} " +
|
||||
"#{actor.release_path} && " +
|
||||
"#{mercurial} -R #{actor.release_path} update " +
|
||||
"-C #{configuration.revision} &&"
|
||||
run_checkout(actor, command, &hg_stream_handler(actor))
|
||||
end
|
||||
|
||||
private
|
||||
def mercurial
|
||||
configuration[:mercurial] || "hg"
|
||||
end
|
||||
|
||||
def hg_stream_handler(actor)
|
||||
Proc.new do |ch, stream, out|
|
||||
prefix = "#{stream} :: #{ch[:host]}"
|
||||
actor.logger.info out, prefix
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue