aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2005-08-12 21:40:38 +0000
committerJamis Buck <jamis@37signals.com>2005-08-12 21:40:38 +0000
commit67f73c99dbd655c7ef6b71a0f0721902093ce855 (patch)
treefdcc17990d8e22a74f221902658ba91c3e43f809
parent6500981d608a046305898fefdcebf293553468ae (diff)
downloadrails-67f73c99dbd655c7ef6b71a0f0721902093ce855.tar.gz
rails-67f73c99dbd655c7ef6b71a0f0721902093ce855.tar.bz2
rails-67f73c99dbd655c7ef6b71a0f0721902093ce855.zip
Subversion module recognizes the password prompt for HTTP authentication
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1997 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--switchtower/CHANGELOG2
-rw-r--r--switchtower/Rakefile2
-rw-r--r--switchtower/lib/switchtower/scm/subversion.rb10
-rw-r--r--switchtower/test/scm/subversion_test.rb118
4 files changed, 126 insertions, 6 deletions
diff --git a/switchtower/CHANGELOG b/switchtower/CHANGELOG
index 5447b07e07..c645bff275 100644
--- a/switchtower/CHANGELOG
+++ b/switchtower/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Subversion module recognizes the password prompt for HTTP authentication
+
* Preserve +x on scripts when using darcs #1929 [Scott Barron]
* When executing multiline commands, use a backslash to escape the newline
diff --git a/switchtower/Rakefile b/switchtower/Rakefile
index 2e99a99244..69ac03c9a0 100644
--- a/switchtower/Rakefile
+++ b/switchtower/Rakefile
@@ -15,7 +15,7 @@ desc "Build documentation"
task :doc => [ :rdoc ]
Rake::TestTask.new do |t|
- t.test_files = Dir["test/*_test.rb"]
+ t.test_files = Dir["test/**/*_test.rb"]
t.verbose = true
end
diff --git a/switchtower/lib/switchtower/scm/subversion.rb b/switchtower/lib/switchtower/scm/subversion.rb
index 79cb6aef8f..cc5d78c3e6 100644
--- a/switchtower/lib/switchtower/scm/subversion.rb
+++ b/switchtower/lib/switchtower/scm/subversion.rb
@@ -27,7 +27,8 @@ module SwitchTower
configuration.logger.debug "querying latest revision..." unless @latest_revision
repo = configuration.repository
until @latest_revision
- @latest_revision = latest_revision_at(repo)
+ match = svn_log(repo).scan(/r(\d+)/).first
+ @latest_revision = match ? match.first : nil
if @latest_revision.nil?
# if a revision number was not reported, move up a level in the path
# and try again.
@@ -55,7 +56,7 @@ module SwitchTower
actor.run(command) do |ch, stream, out|
prefix = "#{stream} :: #{ch[:host]}"
actor.logger.info out, prefix
- if out =~ /^Password:/
+ if out =~ /^Password.*:/
actor.logger.info "subversion is asking for a password", prefix
ch.send_data "#{actor.password}\n"
elsif out =~ %r{\(yes/no\)}
@@ -76,9 +77,8 @@ module SwitchTower
private
- def latest_revision_at(path)
- match = `svn log -q -rhead #{path}`.scan(/r(\d+)/).first
- match ? match.first : nil
+ def svn_log(path)
+ `svn log -q -rhead #{path}`
end
end
diff --git a/switchtower/test/scm/subversion_test.rb b/switchtower/test/scm/subversion_test.rb
new file mode 100644
index 0000000000..47942d9b9c
--- /dev/null
+++ b/switchtower/test/scm/subversion_test.rb
@@ -0,0 +1,118 @@
+$:.unshift File.dirname(__FILE__) + "/../../lib"
+
+require 'test/unit'
+require 'switchtower/scm/subversion'
+
+class ScmSubversionTest < Test::Unit::TestCase
+ class MockLogger
+ def info(msg,pfx=nil) end
+ def debug(msg,pfx=nil) end
+ end
+
+ class MockConfiguration < Hash
+ def logger
+ @logger ||= MockLogger.new
+ end
+
+ def method_missing(sym, *args)
+ if args.length == 0
+ self[sym]
+ else
+ super
+ end
+ end
+ end
+
+ class SubversionTest < SwitchTower::SCM::Subversion
+ attr_accessor :story
+ attr_reader :last_path
+
+ def svn_log(path)
+ @last_path = path
+ story.shift
+ end
+ end
+
+ class MockChannel
+ attr_reader :sent_data
+
+ def send_data(data)
+ @sent_data ||= []
+ @sent_data << data
+ end
+
+ def [](name)
+ "value"
+ end
+ end
+
+ class MockActor
+ attr_reader :command
+ attr_reader :channels
+ attr_accessor :story
+
+ def initialize(config)
+ @config = config
+ end
+
+ def run(command)
+ @command = command
+ @channels ||= []
+ @channels << MockChannel.new
+ story.each { |stream, line| yield @channels.last, stream, line }
+ end
+
+ def method_missing(sym, *args)
+ @config.send(sym, *args)
+ end
+ end
+
+ def setup
+ @config = MockConfiguration.new
+ @config[:repository] = "/hello/world"
+ @config[:svn] = "/path/to/svn"
+ @config[:password] = "chocolatebrownies"
+ @scm = SubversionTest.new(@config)
+ @actor = MockActor.new(@config)
+ @log_msg = <<MSG.strip
+------------------------------------------------------------------------
+r1967 | minam | 2005-08-03 06:59:03 -0600 (Wed, 03 Aug 2005) | 2 lines
+
+Initial commit of the new switchtower utility
+
+------------------------------------------------------------------------
+MSG
+ @scm.story = [ @log_msg ]
+ end
+
+ def test_latest_revision
+ @scm.story = [ @log_msg ]
+ assert_equal "1967", @scm.latest_revision
+ assert_equal "/hello/world", @scm.last_path
+ end
+
+ def test_latest_revision_searching_upwards
+ @scm.story = [ "-----------------------------\n", @log_msg ]
+ assert_equal "1967", @scm.latest_revision
+ assert_equal "/hello", @scm.last_path
+ end
+
+ def test_checkout
+ @actor.story = []
+ assert_nothing_raised { @scm.checkout(@actor) }
+ assert_nil @actor.channels.last.sent_data
+ assert_match %r{/path/to/svn}, @actor.command
+ end
+
+ def test_checkout_needs_ssh_password
+ @actor.story = [[:out, "Password: "]]
+ assert_nothing_raised { @scm.checkout(@actor) }
+ assert_equal ["chocolatebrownies\n"], @actor.channels.last.sent_data
+ end
+
+ def test_checkout_needs_http_password
+ @actor.story = [[:out, "Password for (something): "]]
+ assert_nothing_raised { @scm.checkout(@actor) }
+ assert_equal ["chocolatebrownies\n"], @actor.channels.last.sent_data
+ end
+end