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.
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/switchtower/scm/subversion.rb', line 69 def checkout(actor) svn = configuration[:svn] ? configuration[:svn] : "svn" command = "#{svn} co -q -r#{configuration.revision} #{configuration.repository} #{actor.release_path};" run_checkout(actor, command) do |ch, stream, out| prefix = "#{stream} :: #{ch[:host]}" actor.logger.info out, prefix if out =~ /^Password.*:/ actor.logger.info "subversion is asking for a password", prefix ch.send_data "#{actor.password}\n" elsif out =~ %r{\(yes/no\)} actor.logger.info "subversion is asking whether to connect or not", prefix ch.send_data "yes\n" elsif out =~ %r{passphrase} = "subversion needs your key's passphrase, sending empty string" actor.logger.info , prefix ch.send_data "\n" elsif out =~ %r{The entry \'(\w+)\' is no longer a directory} = "subversion can't update because directory '#{$1}' was replaced. Please add it to svn:ignore." actor.logger.info , prefix raise end end 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 |