Class: SwitchTower::SCM::Subversion
- Defined in:
- lib/switchtower/scm/subversion.rb
Overview
An SCM module for using subversion as your source control tool. This module is used by default, but you can explicitly specify it by placing the following line in your configuration:
set :scm, :subversion
Also, this module accepts a :svn
configuration variable, which (if specified) will be used as the full path to the svn executable on the remote machine:
set :svn, "/opt/local/bin/svn"
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#checkout(actor) ⇒ Object
Check out (on all servers associated with the current task) the latest revision.
-
#current_revision(actor) ⇒ Object
Return the number of the revision currently deployed.
-
#diff(actor, from = nil, to = nil) ⇒ Object
Return a string containing the diff between the two revisions.
-
#latest_revision ⇒ Object
Return an integer identifying the last known revision in the svn repository.
-
#update(actor) ⇒ Object
Update the current release in-place.
Methods inherited from Base
Constructor Details
This class inherits a constructor from SwitchTower::SCM::Base
Instance Method Details
#checkout(actor) ⇒ Object
Check out (on all servers associated with the current task) the latest revision. Uses the given actor instance to execute the command. If svn 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.)
69 70 71 72 73 74 |
# File 'lib/switchtower/scm/subversion.rb', line 69 def checkout(actor) op = configuration[:checkout] || "co" username = configuration[:svn_username] ? "--username #{configuration[:svn_username]}" : "" command = "#{svn} #{op} #{username} -q -r#{configuration.revision} #{configuration.repository} #{actor.release_path} &&" run_checkout(actor, command, &svn_stream_handler(actor)) end |
#current_revision(actor) ⇒ Object
Return the number of the revision currently deployed.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/switchtower/scm/subversion.rb', line 38 def current_revision(actor) 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 revision" if str == :err end date, time, user, rev, dir = result.split raise "current revision not found in revisions.log" unless dir == latest rev.to_i end |
#diff(actor, from = nil, to = nil) ⇒ Object
Return a string containing the diff between the two revisions. from
and to
may be in any format that svn recognizes as a valid revision identifier. If from
is nil
, it defaults to the last deployed revision. If to
is nil
, it defaults to HEAD.
57 58 59 60 61 62 |
# File 'lib/switchtower/scm/subversion.rb', line 57 def diff(actor, from=nil, to=nil) from ||= current_revision(actor) to ||= "HEAD" `svn diff #{configuration.repository}@#{from} #{configuration.repository}@#{to}` end |
#latest_revision ⇒ Object
Return an integer identifying the last known revision in the svn repository. (This integer is currently the revision number.) If latest revision does not exist in the given repository, this routine will walk up the directory tree until it finds it.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/switchtower/scm/subversion.rb', line 22 def latest_revision configuration.logger.debug "querying latest revision..." unless @latest_revision repo = configuration.repository until @latest_revision match = svn_log(repo).scan(/r(\d+)/).first @latest_revision = match ? match.first : nil if @latest_revision.nil? # if a revision number was not reported, move up a level in the path # and try again. repo = File.dirname(repo) end end @latest_revision end |
#update(actor) ⇒ Object
Update the current release in-place. This assumes that the original deployment was made using checkout, and not something like export.
78 79 80 81 |
# File 'lib/switchtower/scm/subversion.rb', line 78 def update(actor) command = "cd #{actor.current_path} && #{svn} up -q &&" run_update(actor, command, &svn_stream_handler(actor)) end |