1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

Add branch support to CVS (closes #3596)

git-svn-id: http://svn.rubyonrails.org/rails/tools/switchtower@3490 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jamis Buck 2006-01-28 15:58:04 +00:00
parent 146484da6b
commit 3d98ce91e3
5 changed files with 80 additions and 7 deletions

View file

@ -1,5 +1,7 @@
*0.11.0* *SVN* *0.11.0* *SVN*
* Add branch support to CVS [jeremy@hinegardner.org] (#3596)
* Add bazaar-ng SCM module [Damien Merenne] * Add bazaar-ng SCM module [Damien Merenne]
* Add optional :svn_username and :svn_password variables * Add optional :svn_username and :svn_password variables

View file

@ -19,6 +19,7 @@ desc "Build documentation"
task :doc => [ :rdoc ] task :doc => [ :rdoc ]
Rake::TestTask.new do |t| Rake::TestTask.new do |t|
t.ruby_opts << "-rubygems"
t.test_files = Dir["test/**/*_test.rb"] t.test_files = Dir["test/**/*_test.rb"]
t.verbose = true t.verbose = true
end end

View file

@ -19,10 +19,27 @@ module SwitchTower
# the revisions, etc.) via the <tt>:local</tt> variable, which defaults to # the revisions, etc.) via the <tt>:local</tt> variable, which defaults to
# ".". # ".".
# #
# You may also specify a <tt>:branch</tt> configuration variable,
# which (if specified) will be used in the '-r' option to the cvs
# check out command. If it is not set, the module will determine if a
# branch is being used in the CVS sandbox relative to
# <tt>:local</tt> and act accordingly.
#
# set :branch, "prod-20060124"
#
# Also, you can specify the CVS_RSH variable to use on the remote machine(s) # Also, you can specify the CVS_RSH variable to use on the remote machine(s)
# via the <tt>:cvs_rsh</tt> variable. This defaults to the value of the # via the <tt>:cvs_rsh</tt> variable. This defaults to the value of the
# CVS_RSH environment variable locally, or if it is not set, to "ssh". # CVS_RSH environment variable locally, or if it is not set, to "ssh".
class Cvs < Base 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
# Return a string representing the date of the last revision (CVS is # 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 # seriously retarded, in that it does not give you a way to query when
# the last revision was made to the repository, so this is a fairly # the last revision was made to the repository, so this is a fairly
@ -30,22 +47,37 @@ module SwitchTower
def latest_revision def latest_revision
return @latest_revision if @latest_revision return @latest_revision if @latest_revision
configuration.logger.debug "querying latest revision..." configuration.logger.debug "querying latest revision..."
@latest_revision = cvs_log(configuration.local). @latest_revision = cvs_log(configuration.local,configuration.branch).
split(/\r?\n/). split(/\r?\n/).
grep(/^date: (.*?);/) { Time.parse($1).strftime("%Y-%m-%d %H:%M:%S") }. grep(/^date: (.*?);/) { Time.parse($1).strftime("%Y-%m-%d %H:%M:%S") }.
sort. sort.
last last
end end
# Return a string representing the branch that the sandbox
# relative to <tt>:local</tt> contains.
def current_branch
return @current_branch if @current_branch
configuration.logger.debug "determining current_branch..."
@current_branch = cvs_branch(configuration.local)
end
# Check out (on all servers associated with the current task) the latest # Check out (on all servers associated with the current task) the latest
# revision. Uses the given actor instance to execute the command. # revision, using a branch if necessary. Uses the given actor instance
# to execute the command.
def checkout(actor) def checkout(actor)
cvs = configuration[:cvs] || "cvs" cvs = configuration[:cvs] || "cvs"
cvs_rsh = configuration[:cvs_rsh] || ENV['CVS_RSH'] || "ssh" cvs_rsh = configuration[:cvs_rsh] || ENV['CVS_RSH'] || "ssh"
if "HEAD" == configuration.branch then
branch_option = ""
else
branch_option = "-r #{configuration.branch}"
end
command = <<-CMD command = <<-CMD
cd #{configuration.releases_path}; cd #{configuration.releases_path};
CVS_RSH="#{cvs_rsh}" #{cvs} -d #{configuration.repository} -Q co -D "#{configuration.revision}" -d #{File.basename(actor.release_path)} #{actor.application}; CVS_RSH="#{cvs_rsh}" #{cvs} -d #{configuration.repository} -Q co -D "#{configuration.revision}" #{branch_option} -d #{File.basename(actor.release_path)} #{actor.application};
CMD CMD
run_checkout(actor, command) do |ch, stream, out| run_checkout(actor, command) do |ch, stream, out|
@ -64,8 +96,23 @@ module SwitchTower
private private
def cvs_log(path) # Look for a 'CVS/Tag' file in the path. If this file exists
`cd #{path || "."} && cvs -q log -N -rHEAD` # 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
end
branch
end
def cvs_log(path,branch)
`cd #{path || "."} && cvs -q log -N -r#{branch}`
end end
end end

View file

@ -9,10 +9,15 @@ class ScmCvsTest < Test::Unit::TestCase
attr_accessor :story attr_accessor :story
attr_reader :last_path attr_reader :last_path
def cvs_log(path) def cvs_log(path,branch)
@last_path = path @last_path = path
story.shift story.shift
end end
def cvs_branch(path)
"deploy-me"
end
end end
class MockChannel class MockChannel
@ -161,4 +166,14 @@ MSG
assert_nothing_raised { @scm.checkout(@actor) } assert_nothing_raised { @scm.checkout(@actor) }
assert_equal ["chocolatebrownies\n"], @actor.channels.last.sent_data assert_equal ["chocolatebrownies\n"], @actor.channels.last.sent_data
end end
def test_current_branch
assert_equal "deploy-me", @scm.current_branch
end
def test_default_current_branch
@config[:branch] = "default-branch"
@scm = CvsTest.new(@config)
assert_equal "default-branch", @scm.current_branch
end
end end

View file

@ -32,6 +32,14 @@ class MockConfiguration < Hash
@logger ||= MockLogger.new @logger ||= MockLogger.new
end end
def set(variable, value=nil, &block)
self[variable] = value
end
def respond_to?(sym)
self.has_key?(sym)
end
def method_missing(sym, *args) def method_missing(sym, *args)
if args.length == 0 if args.length == 0
self[sym] self[sym]