From 146484da6b878448c5b8ebc07082d605ac27a952 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Sat, 28 Jan 2006 15:52:07 +0000 Subject: [PATCH] Add bazaar-ng SCM module [Damien Merenne] git-svn-id: http://svn.rubyonrails.org/rails/tools/switchtower@3489 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- CHANGELOG | 2 ++ THANKS | 3 +- lib/switchtower/scm/bzr.rb | 70 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 lib/switchtower/scm/bzr.rb diff --git a/CHANGELOG b/CHANGELOG index 67138057..988ebb4f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *0.11.0* *SVN* +* Add bazaar-ng SCM module [Damien Merenne] + * Add optional :svn_username and :svn_password variables * Allow Proc-valued variables to be set more conveniently (set(:foo) { "bar" }) diff --git a/THANKS b/THANKS index 80d83e9a..2e087547 100644 --- a/THANKS +++ b/THANKS @@ -1,2 +1,3 @@ * Bazaar (v1) SCM Module: Edd Dumbill -* Perforce SCM Module: Richard McMahon \ No newline at end of file +* Perforce SCM Module: Richard McMahon +* Bazaar-NG SCM Module: Damien Merenne \ No newline at end of file diff --git a/lib/switchtower/scm/bzr.rb b/lib/switchtower/scm/bzr.rb new file mode 100644 index 00000000..4b10c03d --- /dev/null +++ b/lib/switchtower/scm/bzr.rb @@ -0,0 +1,70 @@ +require 'switchtower/scm/base' + +module SwitchTower + module SCM + + # An SCM module for using Bazaar-NG (bzr) as your source control tool. + # You can use it by placing the following line in your configuration: + # + # set :scm, :bzr + # + # Also, this module accepts a :bzr configuration variable, + # which (if specified) will be used as the full path to the bzr + # executable on the remote machine: + # + # set :bzr, "/opt/local/bin/bzr" + class Bzr < Base + # Return an integer identifying the last known revision in the bzr + # repository. (This integer is currently the revision number.) + def latest_revision + `#{bzr} revno #{configuration.repository}`.to_i + end + + # Return the number of the revision currently deployed. + def current_revision(actor) + command = "#{bzr} revno #{actor.release_path} &&" + run_update(actor, command, &bzr_stream_handler(actor)) + end + + # Return a string containing the diff between the two revisions. +from+ + # and +to+ may be in any format that bzr recognizes as a valid revision + # identifier. If +from+ is +nil+, it defaults to the last deployed + # revision. If +to+ is +nil+, it defaults to the last developed revision. + # Pay attention to the fact that as of now bzr does NOT support + # diff on remote locations. + def diff(actor, from=nil, to=nil) + from ||= current_revision(actor) + to ||= "" + `#{bzr} diff -r #{from}..#{to} #{configuration.repository}` + end + + # Check out (on all servers associated with the current task) the latest + # revision. Uses the given actor instance to execute the command. If + # bzr 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.) + def checkout(actor) + op = configuration[:checkout] || "branch" + command = "#{bzr} #{op} -r#{configuration.revision} #{configuration.repository} #{actor.release_path} &&" + run_checkout(actor, command, &bzr_stream_handler(actor)) + end + + def update(actor) + command = "cd #{actor.current_path} && #{bzr} pull -q &&" + run_update(actor, command, &bzr_stream_handler(actor)) + end + + private + def bzr + configuration[:bzr] || "bzr" + end + + def bzr_stream_handler(actor) + Proc.new do |ch, stream, out| + prefix = "#{stream} :: #{ch[:host]}" + actor.logger.info out, prefix + end + end + end + end +end