Skip to content

Commit

Permalink
switchtower: add diff_from_last_deploy task (currently only works wit…
Browse files Browse the repository at this point in the history
…h subversion)

git-svn-id: http://svn.rubyonrails.org/rails/tools/switchtower@2452 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jamis committed Oct 4, 2005
1 parent f06e875 commit 8a163ef
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -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.
Expand Down
11 changes: 11 additions & 0 deletions lib/switchtower/recipes/standard.rb
Expand Up @@ -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
8 changes: 8 additions & 0 deletions lib/switchtower/scm/base.rb
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions lib/switchtower/scm/subversion.rb
Expand Up @@ -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
Expand Down

0 comments on commit 8a163ef

Please sign in to comment.