Permalink
Browse files

switchtower: add diff_from_last_deploy task (currently only works wit…

…h subversion)

git-svn-id: http://svn.rubyonrails.org/rails/tools/switchtower@2452 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent f06e875 commit 8a163ef75e368bc7f7ed9e675057ba49ceda16e4 @jamis jamis committed Oct 4, 2005
Showing with 48 additions and 0 deletions.
  1. +2 −0 CHANGELOG
  2. +11 −0 lib/switchtower/recipes/standard.rb
  3. +8 −0 lib/switchtower/scm/base.rb
  4. +27 −0 lib/switchtower/scm/subversion.rb
View
@@ -1,5 +1,7 @@
*SVN*
+* Add diff_from_last_deploy task (currently only works with subversion)
+
* Add deploy_with_migrations task.
* Make the migrate task more customizable.
@@ -162,3 +162,14 @@
rollback_code
restart
end
+
+desc <<DESC
+Displays the diff between HEAD and what was last deployed. (Not available
+with all SCM's.)
+DESC
+task :diff_from_last_deploy do
+ diff = source.diff(self)
+ puts
+ puts diff
+ puts
+end
@@ -13,6 +13,14 @@ def latest_revision
nil
end
+ def current_revision(actor)
+ raise "#{self.class} doesn't support querying the deployed revision"
+ end
+
+ def diff(actor, from=nil, to=nil)
+ raise "#{self.class} doesn't support diff(from, to)"
+ end
+
private
def run_checkout(actor, guts, &block)
@@ -34,6 +34,33 @@ def latest_revision
@latest_revision
end
+ # Return the number of the revision currently deployed.
+ 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
+
+ # 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.
+ def diff(actor, from=nil, to=nil)
+ from ||= current_revision(actor)
+ to ||= "HEAD"
+
+ `svn diff #{configuration.repository}@#{from} #{configuration.repository}@#{to}`
+ end
+
# 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

0 comments on commit 8a163ef

Please sign in to comment.