Class: SwitchTower::SCM::Baz

Inherits:
Base
  • Object
show all
Defined in:
lib/switchtower/scm/baz.rb

Overview

An SCM module for using Bazaar 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, :baz

Also, this module accepts a :baz configuration variable, which (if specified) will be used as the full path to the svn executable on the remote machine:

set :baz, "/opt/local/bin/baz"

Set the version you wish to deploy as the repository variable, for example:

set :repository, "[email protected]/yourstuff--trunk--1.0"

Ensure that you have already registered the archive on the target machines.

As bazaar keeps a great deal of extra information on a checkout, you will probably want to use export instead:

set :checkout, "export"

TODO: provide setup recipe to register archive

Instance Attribute Summary

Attributes inherited from Base

#configuration

Instance Method Summary collapse

Methods inherited from Base

#initialize

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.



69
70
71
72
73
74
# File 'lib/switchtower/scm/baz.rb', line 69

def checkout(actor)
  op = configuration[:checkout] || "get"
  from = baz_revision_name(configuration.revision)
  command = "#{baz} #{op} #{configuration.repository}--#{from} #{actor.release_path} &&"
  run_checkout(actor, command, &baz_stream_handler(actor)) 
end

#current_revision(actor) ⇒ Object

Return the number of the revision currently deployed.



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/switchtower/scm/baz.rb', line 41

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 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.



59
60
61
62
63
64
65
# File 'lib/switchtower/scm/baz.rb', line 59

def diff(actor, from=nil, to=nil)
  from ||= current_revision(actor)
  to ||= latest_revision
  from = baz_revision_name(from)
  to = baz_revision_name(to)
  `#{baz} delta --diffs -A #{baz_archive} #{baz_version}--#{from} #{baz_version}--#{to}`
end

#latest_revisionObject

Return an integer identifying the last known revision in the baz repository. (This integer is currently the revision number.)



35
36
37
38
# File 'lib/switchtower/scm/baz.rb', line 35

def latest_revision
  `#{baz} revisions #{configuration.repository}`.split.last =~ /\-(\d+)$/
  $1
end

#update(actor) ⇒ Object



76
77
78
79
# File 'lib/switchtower/scm/baz.rb', line 76

def update(actor)
  command = "cd #{actor.current_path} && #{baz} update &&"
  run_update(actor, command, &baz_stream_handler(actor)) 
end