diff --git a/CHANGELOG b/CHANGELOG index 2a1ea443..884dcd50 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *0.11.0* *SVN* +* Make CVS module's :local value default to "." + * Add "invoke" task for executing one-off commands * Make port selection smarter for gateway connections diff --git a/lib/switchtower/scm/cvs.rb b/lib/switchtower/scm/cvs.rb index 3a8ea97c..082574b4 100644 --- a/lib/switchtower/scm/cvs.rb +++ b/lib/switchtower/scm/cvs.rb @@ -32,13 +32,13 @@ module SwitchTower # CVS_RSH environment variable locally, or if it is not set, to "ssh". class Cvs < Base def initialize(configuration) - super(configuration) - if not @configuration.respond_to?(:branch) then - @configuration.set(:branch) { self.current_branch } - else - @current_branch = @configuration[:branch] - end - end + super(configuration) + if not configuration.respond_to?(:branch) then + configuration.set(:branch) { self.current_branch } + else + @current_branch = configuration[:branch] + end + end # Return a string representing the date of the last revision (CVS is # seriously retarded, in that it does not give you a way to query when @@ -47,7 +47,7 @@ module SwitchTower def latest_revision return @latest_revision if @latest_revision configuration.logger.debug "querying latest revision..." - @latest_revision = cvs_log(configuration.local,configuration.branch). + @latest_revision = cvs_log(cvs_local, configuration.branch). split(/\r?\n/). grep(/^date: (.*?);/) { Time.parse($1).strftime("%Y-%m-%d %H:%M:%S") }. sort. @@ -57,9 +57,9 @@ module SwitchTower # Return a string representing the branch that the sandbox # relative to :local contains. def current_branch - return @current_branch if @current_branch - configuration.logger.debug "determining current_branch..." - @current_branch = cvs_branch(configuration.local) + return @current_branch if @current_branch + configuration.logger.debug "determining current_branch..." + @current_branch = cvs_branch(cvs_local) end # Check out (on all servers associated with the current task) the latest @@ -100,20 +100,24 @@ module SwitchTower # and contains a Line starting with 'T' then this CVS sandbox is # 'tagged' with a branch. In the default case return 'HEAD' def cvs_branch(path) - branch = "HEAD" - branch_file = File.join(path || ".", "CVS", "Tag") - if File.exists?(branch_file) then - File.open(branch_file) do |f| - possible_branch = f.find { |l| l =~ %r{^T} } - branch = possible_branch.strip[1..-1] if possible_branch - end + branch = "HEAD" + branch_file = File.join(path || ".", "CVS", "Tag") + if File.exists?(branch_file) then + File.open(branch_file) do |f| + possible_branch = f.find { |l| l =~ %r{^T} } + branch = possible_branch.strip[1..-1] if possible_branch end - branch + end + branch end def cvs_log(path,branch) `cd #{path || "."} && cvs -q log -N -r#{branch}` end + + def cvs_local + configuration.local || "." + end end end diff --git a/test/scm/cvs_test.rb b/test/scm/cvs_test.rb index 209ec5e1..50e0c6e7 100644 --- a/test/scm/cvs_test.rb +++ b/test/scm/cvs_test.rb @@ -61,7 +61,6 @@ class ScmCvsTest < Test::Unit::TestCase def setup @config = MockConfiguration.new @config[:repository] = ":ext:joetester@rubyforge.org:/hello/world" - @config[:local] = "/hello/world" @config[:cvs] = "/path/to/cvs" @config[:password] = "chocolatebrownies" @config[:now] = Time.utc(2005,8,24,12,0,0) @@ -149,11 +148,19 @@ MSG end def test_latest_revision + @config[:local] = "/hello/world" @scm.story = [ @log_msg ] assert_equal "2004-10-12 02:21:02", @scm.latest_revision assert_equal "/hello/world", @scm.last_path end + def test_latest_with_default_local + @config[:local] = nil + @scm.story = [ @log_msg ] + assert_equal "2004-10-12 02:21:02", @scm.latest_revision + assert_equal ".", @scm.last_path + end + def test_checkout @actor.story = [] assert_nothing_raised { @scm.checkout(@actor) }