piston 1.4.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/History.txt +24 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +109 -0
  4. data/{README → README.txt} +14 -10
  5. data/VERSION.yml +4 -0
  6. data/bin/piston +3 -8
  7. data/lib/piston/cli.rb +121 -0
  8. data/lib/piston/commands/base.rb +44 -0
  9. data/lib/piston/commands/convert.rb +23 -71
  10. data/lib/piston/commands/diff.rb +14 -46
  11. data/lib/piston/commands/import.rb +48 -57
  12. data/lib/piston/commands/info.rb +24 -0
  13. data/lib/piston/commands/lock_unlock.rb +26 -0
  14. data/lib/piston/commands/status.rb +29 -54
  15. data/lib/piston/commands/update.rb +35 -122
  16. data/lib/piston/commands/upgrade.rb +26 -0
  17. data/lib/piston/commands.rb +4 -0
  18. data/lib/piston/git/client.rb +76 -0
  19. data/lib/piston/git/commit.rb +114 -0
  20. data/lib/piston/git/repository.rb +63 -0
  21. data/lib/piston/git/working_copy.rb +145 -0
  22. data/lib/piston/git.rb +13 -0
  23. data/lib/piston/repository.rb +61 -0
  24. data/lib/piston/revision.rb +83 -0
  25. data/lib/piston/svn/client.rb +88 -0
  26. data/lib/piston/svn/repository.rb +67 -0
  27. data/lib/piston/svn/revision.rb +112 -0
  28. data/lib/piston/svn/working_copy.rb +184 -0
  29. data/lib/piston/svn.rb +15 -0
  30. data/lib/piston/version.rb +9 -7
  31. data/lib/piston/working_copy.rb +334 -0
  32. data/lib/piston.rb +13 -64
  33. data/lib/subclass_responsibility_error.rb +2 -0
  34. data/test/integration_helpers.rb +36 -0
  35. data/test/spec_suite.rb +4 -0
  36. data/test/test_helper.rb +92 -0
  37. data/test/unit/git/commit/test_checkout.rb +31 -0
  38. data/test/unit/git/commit/test_each.rb +30 -0
  39. data/test/unit/git/commit/test_rememberance.rb +22 -0
  40. data/test/unit/git/commit/test_validation.rb +34 -0
  41. data/test/unit/git/repository/test_at.rb +23 -0
  42. data/test/unit/git/repository/test_basename.rb +12 -0
  43. data/test/unit/git/repository/test_branchanme.rb +15 -0
  44. data/test/unit/git/repository/test_guessing.rb +32 -0
  45. data/test/unit/git/working_copy/test_copying.rb +25 -0
  46. data/test/unit/git/working_copy/test_creation.rb +22 -0
  47. data/test/unit/git/working_copy/test_existence.rb +18 -0
  48. data/test/unit/git/working_copy/test_finalization.rb +15 -0
  49. data/test/unit/git/working_copy/test_guessing.rb +35 -0
  50. data/test/unit/git/working_copy/test_rememberance.rb +22 -0
  51. data/test/unit/svn/repository/test_at.rb +19 -0
  52. data/test/unit/svn/repository/test_basename.rb +24 -0
  53. data/test/unit/svn/repository/test_guessing.rb +45 -0
  54. data/test/unit/svn/revision/test_checkout.rb +28 -0
  55. data/test/unit/svn/revision/test_each.rb +22 -0
  56. data/test/unit/svn/revision/test_rememberance.rb +38 -0
  57. data/test/unit/svn/revision/test_validation.rb +50 -0
  58. data/test/unit/svn/working_copy/test_copying.rb +26 -0
  59. data/test/unit/svn/working_copy/test_creation.rb +16 -0
  60. data/test/unit/svn/working_copy/test_existence.rb +23 -0
  61. data/test/unit/svn/working_copy/test_externals.rb +56 -0
  62. data/test/unit/svn/working_copy/test_finalization.rb +17 -0
  63. data/test/unit/svn/working_copy/test_guessing.rb +18 -0
  64. data/test/unit/svn/working_copy/test_rememberance.rb +26 -0
  65. data/test/unit/test_info.rb +37 -0
  66. data/test/unit/test_lock_unlock.rb +47 -0
  67. data/test/unit/test_repository.rb +51 -0
  68. data/test/unit/test_revision.rb +31 -0
  69. data/test/unit/working_copy/test_guessing.rb +35 -0
  70. data/test/unit/working_copy/test_info.rb +14 -0
  71. data/test/unit/working_copy/test_rememberance.rb +42 -0
  72. data/test/unit/working_copy/test_validate.rb +63 -0
  73. metadata +132 -31
  74. data/CHANGELOG +0 -81
  75. data/LICENSE +0 -19
  76. data/Rakefile +0 -63
  77. data/contrib/piston +0 -43
  78. data/lib/core_ext/range.rb +0 -5
  79. data/lib/core_ext/string.rb +0 -9
  80. data/lib/piston/command.rb +0 -68
  81. data/lib/piston/command_error.rb +0 -6
  82. data/lib/piston/commands/lock.rb +0 -30
  83. data/lib/piston/commands/switch.rb +0 -139
  84. data/lib/piston/commands/unlock.rb +0 -29
  85. data/lib/transat/parser.rb +0 -189
@@ -0,0 +1,92 @@
1
+ require "test/unit"
2
+ require "rubygems"
3
+ require "mocha"
4
+ require "log4r"
5
+ require "fileutils"
6
+ require "pathname"
7
+ require "piston"
8
+ require "active_support"
9
+
10
+ begin
11
+ require "turn"
12
+ rescue LoadError
13
+ # NOP: ignore, this is not a real dependency
14
+ end
15
+
16
+ require File.expand_path("#{File.dirname(__FILE__)}/integration_helpers")
17
+ require "find"
18
+
19
+ module Test
20
+ module Unit
21
+ module Assertions
22
+ def deny(boolean, message = nil)
23
+ message = build_message message, '<?> is not false or nil.', boolean
24
+ assert_block message do
25
+ not boolean
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ class Piston::TestCase < Test::Unit::TestCase
33
+ class << self
34
+ def logger
35
+ @@logger ||= Log4r::Logger["test"]
36
+ end
37
+ end
38
+
39
+ attr_reader :pathnames
40
+ def setup
41
+ super
42
+ @pathnames = []
43
+ end
44
+
45
+ def teardown
46
+ pathnames.each do |pathname|
47
+ pathname.rmtree if File.exists?(pathname)
48
+ end
49
+ super
50
+ end
51
+
52
+ def run(*args)
53
+ test_name = if self.respond_to?(:name) then
54
+ name
55
+ elsif self.respond_to?(:method_name) then
56
+ method_name
57
+ else
58
+ raise "Don't know how to get the test's name: neither #name or #method_name is available"
59
+ end
60
+ return if test_name.to_sym == :default_test && self.class == Piston::TestCase
61
+ super
62
+ end
63
+
64
+ def mkpath(path_or_pathname)
65
+ returning(path_or_pathname.is_a?(Pathname) ? path_or_pathname : Pathname.new(File.expand_path(path_or_pathname))) do |path|
66
+ path.mkpath
67
+ pathnames.push(path)
68
+ end
69
+ end
70
+
71
+ def logger
72
+ self.class.logger
73
+ end
74
+ end
75
+
76
+ LOG_DIR = Pathname.new(File.expand_path("#{File.dirname(__FILE__)}/../log")) unless Object::const_defined?(:LOG_DIR)
77
+ LOG_DIR.mkdir rescue nil
78
+
79
+ Log4r::Logger.root.level = Log4r::DEBUG
80
+
81
+ Log4r::Logger.new("main")
82
+ Log4r::Logger.new("handler")
83
+ Log4r::Logger.new("handler::client")
84
+ Log4r::Logger.new("handler::client::out")
85
+ Log4r::Logger.new("test")
86
+
87
+ FileUtils.touch("#{LOG_DIR}/test.log")
88
+ Log4r::FileOutputter.new("log", :trunc => true, :filename => (LOG_DIR + "test.log").realpath.to_s)
89
+
90
+ Log4r::Logger["main"].add "log"
91
+ Log4r::Logger["handler"].add "log"
92
+ Log4r::Logger["test"].add "log"
@@ -0,0 +1,31 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../test_helper")
2
+
3
+ class Piston::Git::TestGitCommitCheckout < Piston::TestCase
4
+ def setup
5
+ super
6
+ @repos = mock("repos")
7
+ @repos.stubs(:url).returns("git://a.repos.com/project.git")
8
+ @reposdir = Pathname.new("tmp/.repos.tmp.git")
9
+ end
10
+
11
+ def test_clones_repository_at_indicated_path
12
+ @sha1 = "a9302"
13
+ @commit = Piston::Git::Commit.new(@repos, @sha1)
14
+ @commit.expects(:git).with(:clone, @repos.url, @reposdir)
15
+ @commit.expects(:git).with(:checkout, "-b", "my-#{@sha1}", @sha1)
16
+ @commit.expects(:git).with(:log, "-n", "1").returns("commit 922b12a6bcbb6f6a2cec60bcf5de17118086080a\nAuthor: Fran\303\247ois Beausoleil <francois@teksol.info>\nDate: Fri Mar 14 13:28:41 2008 -0400\n\n Changed how dependencies are found and managed, by using config/requirements.rb everywhere.\n \n Updated test/test_helper.rb where appropriate.\n")
17
+ Dir.expects(:chdir).with(@reposdir).yields
18
+ @commit.checkout_to(@reposdir)
19
+ end
20
+
21
+ def test_cloning_head_finds_head_commit
22
+ @sha1 = "master"
23
+ @commit = Piston::Git::Commit.new(@repos, @sha1)
24
+ @commit.expects(:git).with(:clone, @repos.url, @reposdir)
25
+ @commit.expects(:git).with(:checkout, "-b", "my-#{@sha1}", @sha1)
26
+ @commit.expects(:git).with(:log, "-n", "1").returns("commit 922b12a6bcbb6f6a2cec60bcf5de17118086080a\nAuthor: Fran\303\247ois Beausoleil <francois@teksol.info>\nDate: Fri Mar 14 13:28:41 2008 -0400\n\n Changed how dependencies are found and managed, by using config/requirements.rb everywhere.\n \n Updated test/test_helper.rb where appropriate.\n")
27
+ Dir.expects(:chdir).with(@reposdir).yields
28
+ @commit.checkout_to(@reposdir)
29
+ assert_equal "922b12a6bcbb6f6a2cec60bcf5de17118086080a", @commit.sha1
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../test_helper")
2
+
3
+ class Piston::Git::TestGitCommitEach < Piston::TestCase
4
+ def setup
5
+ super
6
+ @repos = mock("repository")
7
+ @repos.stubs(:url).returns("git://github.com/francois/arepos.git")
8
+ @tmpdir = mkpath("tmp/.arepos.tmp.git")
9
+
10
+ @commit = Piston::Git::Commit.new(@repos, "ab"*20)
11
+ @commit.stubs(:git).returns("commit " + "ab" * 20)
12
+ @commit.checkout_to(@tmpdir)
13
+ end
14
+
15
+ def test_prunes_search_tree_on_dot_git_directory
16
+ @tmpdir.expects(:find).yields(@tmpdir + ".git")
17
+ assert_throws :prune do
18
+ @commit.each do |relpath|
19
+ # Can't assert anything
20
+ end
21
+ end
22
+ end
23
+
24
+ def test_yields_paths_relative_to_working_copy
25
+ @tmpdir.expects(:find).yields(@tmpdir + "a.rb")
26
+ @commit.each do |relpath|
27
+ assert_equal Pathname.new("a.rb"), relpath
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../test_helper")
2
+
3
+ class Piston::Git::TestGitCommitRememberance < Piston::TestCase
4
+ def setup
5
+ super
6
+ @repos = mock("repository")
7
+ @repos.stubs(:url).returns("git://github.com/francois/arepos.git")
8
+
9
+ @reposdir = Pathname.new("tmp/repos.git")
10
+ @commit = Piston::Git::Commit.new(@repos, "ab"*20)
11
+ @commit.stubs(:git).with("ls-remote", @repos.url, @commit.commit).returns("b"*40)
12
+ @values = @commit.remember_values
13
+ end
14
+
15
+ def test_remembers_original_commit_sha1
16
+ assert_equal @values[Piston::Git::COMMIT], @commit.sha1
17
+ end
18
+
19
+ def test_remembers_original_branch_name
20
+ assert_equal @values[Piston::Git::BRANCH], @commit.revision
21
+ end
22
+ end
@@ -0,0 +1,34 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../test_helper")
2
+
3
+ class Piston::Git::TestGitCommitValidation < Piston::TestCase
4
+ def setup
5
+ super
6
+ @repository = mock("repository")
7
+ @repository.stubs(:url).returns("git://my-git-repos/my-project.git")
8
+ end
9
+
10
+ def test_is_invalid_if_cannot_ls_remote_repository
11
+ commit = new_commit("HEAD")
12
+ commit.expects(:git).with("ls-remote", @repository.url).raises(Piston::Git::Client::CommandError)
13
+ assert_raise Piston::Git::Commit::Gone do
14
+ commit.validate!
15
+ end
16
+ end
17
+
18
+ def test_is_valid_when_ls_remote_succeeds
19
+ commit = new_commit("HEAD")
20
+ commit.expects(:git).with("ls-remote", @repository.url).returns(INFO)
21
+ assert_nothing_raised do
22
+ commit.validate!
23
+ end
24
+ end
25
+
26
+ protected
27
+ def new_commit(commit, recalled_values={})
28
+ Piston::Git::Commit.new(@repository, commit, recalled_values)
29
+ end
30
+
31
+ INFO = <<EOF
32
+ a7c46c702243f145a4089b0cb33d189870f1ae53 HEAD
33
+ EOF
34
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../test_helper")
2
+
3
+ class Piston::Git::TestGitRepositoryAt < Piston::TestCase
4
+ def setup
5
+ super
6
+ @repos = Piston::Git::Repository.new("git://a.repos.com/project.git")
7
+ end
8
+
9
+ def test_returns_a_piston_git_commit
10
+ Piston::Git::Commit.expects(:new).with(@repos, "a93029").returns(commit = mock("commit"))
11
+ assert_equal commit, @repos.at("a93029")
12
+ end
13
+
14
+ def test_returns_a_piston_git_commit_at_head_when_appropriate
15
+ Piston::Git::Commit.expects(:new).with(@repos, "HEAD").returns(commit = mock("commit"))
16
+ assert_equal commit, @repos.at(:head)
17
+ end
18
+
19
+ def test_returns_a_git_commit_using_recalled_values
20
+ Piston::Git::Commit.expects(:new).with(@repos, "a"*40, Piston::Git::COMMIT => "a"*40).returns(commit = mock("commit"))
21
+ assert_equal commit, @repos.at(Piston::Git::COMMIT => "a"*40)
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../test_helper")
2
+
3
+ class Piston::Git::TestGitRepositoryBasename < Piston::TestCase
4
+ def test_basename_is_urls_last_component_minus_dot_git
5
+ assert_equal "piston", basename("git://github.com/francois/piston.git")
6
+ end
7
+
8
+ private
9
+ def basename(url)
10
+ Piston::Git::Repository.new(url).basename
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../test_helper")
2
+
3
+ class Piston::Git::TestGitRepositoryBranchname < Piston::TestCase
4
+ def test_branchname_is_nil_when_no_branch_in_url
5
+ assert_nil Piston::Git::Repository.new("git://github.com/francois/piston.git").branchname
6
+ end
7
+
8
+ def test_branchname_is_branch_when_branch_in_url
9
+ assert_equal "branch", Piston::Git::Repository.new("git://github.com/francois/piston.git?branch").branchname
10
+ end
11
+
12
+ def test_url_does_not_include_branchname
13
+ assert_equal "git://github.com/francois/piston.git", Piston::Git::Repository.new("git://github.com/francois/piston.git?branch").url
14
+ end
15
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../test_helper")
2
+
3
+ class Piston::Git::TestGitRepositoryGuessing < Piston::TestCase
4
+ def test_understands_git_protocol
5
+ assert Piston::Git::Repository.understands_url?("git://github.com/francois/piston.git")
6
+ end
7
+
8
+ def test_understands_git_ssh_protocol
9
+ Piston::Git::Repository.expects(:git).with("ls-remote", "--heads", "git@github.com:francois/piston.git").returns("ab"*20 + " refs/heads/master")
10
+ assert Piston::Git::Repository.understands_url?("git@github.com:francois/piston.git")
11
+ end
12
+
13
+ def test_understand_http_when_heads_returned
14
+ Piston::Git::Repository.expects(:git).with("ls-remote", "--heads", "http://github.com/francois/piston.git").returns("ab"*20 + " refs/heads/master")
15
+ assert Piston::Git::Repository.understands_url?("http://github.com/francois/piston.git")
16
+ end
17
+
18
+ def test_does_not_understand_http_when_no_heads
19
+ Piston::Git::Repository.expects(:git).with("ls-remote", "--heads", "http://github.com/francois/piston.git").returns("")
20
+ deny Piston::Git::Repository.understands_url?("http://github.com/francois/piston.git")
21
+ end
22
+
23
+ def test_asks_url_when_ssh_protocol
24
+ Piston::Git::Repository.expects(:git).with("ls-remote", "--heads", "ssh://francois@github.com/francois/piston.git").returns("ab"*20 + " refs/heads/master")
25
+ assert Piston::Git::Repository.understands_url?("ssh://francois@github.com/francois/piston.git")
26
+ end
27
+
28
+ def test_asks_base_url_when_named_branch_in_url
29
+ Piston::Git::Repository.expects(:git).with("ls-remote", "--heads", "ssh://francois@github.com/francois/piston.git").returns("ab"*20 + " refs/heads/master")
30
+ assert Piston::Git::Repository.understands_url?("ssh://francois@github.com/francois/piston.git?convert")
31
+ end
32
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../test_helper")
2
+
3
+ class Piston::Git::TestGitWorkingCopyCopying < Piston::TestCase
4
+ def setup
5
+ super
6
+ @wcdir = mkpath("tmp/wc")
7
+ @wc = Piston::Git::WorkingCopy.new(@wcdir)
8
+ @wc.stubs(:git)
9
+ end
10
+
11
+ def test_copies_file
12
+ files = ["file.rb"]
13
+ files.expects(:copy_to).with("file.rb", @wcdir + files.first)
14
+ @wc.copy_from(files)
15
+ end
16
+
17
+ def test_ensures_directories_are_created
18
+ files = ["file/a.rb"]
19
+ @wcdir.expects(:+).with(files.first).returns(target = mock("target"))
20
+ target.expects(:dirname).returns(target)
21
+ target.expects(:mkdir)
22
+ files.expects(:copy_to).with("file/a.rb", target)
23
+ @wc.copy_from(files)
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../test_helper")
2
+
3
+ class Piston::Git::TestGitWorkingCopyCreation < Piston::TestCase
4
+ def setup
5
+ super
6
+ @wcdir = mkpath("tmp/wc")
7
+ @wc = Piston::Git::WorkingCopy.new(@wcdir)
8
+ @wc.stubs(:git)
9
+ end
10
+
11
+ def test_create_does_a_simple_mkpath
12
+ @wcdir.expects(:mkpath)
13
+ @wc.create
14
+ end
15
+
16
+ def test_create_succeeds_even_if_mkpath_fails
17
+ @wcdir.expects(:mkpath).raises(Errno::EEXIST)
18
+ assert_nothing_raised do
19
+ @wc.create
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../test_helper")
2
+
3
+ class Piston::Git::TestGitWorkingCopyExistence < Piston::TestCase
4
+ def setup
5
+ super
6
+ @wc = Piston::Git::WorkingCopy.new("tmp/wc")
7
+ @wcdir = @wc.path
8
+ end
9
+
10
+ def test_exist_false_when_no_dir
11
+ deny @wc.exist?
12
+ end
13
+
14
+ def test_exist_true_when_dir_present
15
+ @wcdir.mkdir
16
+ assert @wc.exist?
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../test_helper")
2
+
3
+ class Piston::Git::TestGitWorkingCopyFinalization < Piston::TestCase
4
+ def setup
5
+ super
6
+ @wcdir = mkpath("tmp/wc")
7
+ @wc = Piston::Git::WorkingCopy.new(@wcdir)
8
+ end
9
+
10
+ def test_finalize_adds_path_to_git
11
+ Dir.expects(:chdir).with(@wcdir).yields
12
+ @wc.expects(:git).with(:add, ".")
13
+ @wc.finalize
14
+ end
15
+ end
@@ -0,0 +1,35 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../test_helper")
2
+
3
+ class Piston::Git::TestGitWorkingCopyGuessing < Piston::TestCase
4
+ def setup
5
+ super
6
+ @dir = mkpath("tmp/wc")
7
+ end
8
+
9
+ def test_does_git_status_on_directory
10
+ Dir.expects(:chdir).with(@dir).yields
11
+ Piston::Git::WorkingCopy.expects(:git).with(:status).returns("# On branch master
12
+ nothing to commit (working directory clean)
13
+ ")
14
+ assert Piston::Git::WorkingCopy.understands_dir?(@dir)
15
+ end
16
+
17
+ def test_does_git_status_on_parent_directories_recursively
18
+ @wc = @dir
19
+ @tmp = @wc.parent
20
+ @root = @tmp.parent
21
+
22
+ Dir.expects(:chdir).with(@dir).raises(Errno::ENOENT)
23
+ Dir.expects(:chdir).with(@tmp).raises(Errno::ENOENT)
24
+ Dir.expects(:chdir).with(@root).yields
25
+ Piston::Git::WorkingCopy.expects(:git).with(:status).returns("# On branch master
26
+ nothing to commit (working directory clean)
27
+ ")
28
+ assert Piston::Git::WorkingCopy.understands_dir?(@dir)
29
+ end
30
+
31
+ def test_denies_when_git_unavailable
32
+ Piston::Git::WorkingCopy.stubs(:git).raises(Piston::Git::Client::BadCommand)
33
+ deny Piston::Git::WorkingCopy.understands_dir?(@dir)
34
+ end
35
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../test_helper")
2
+
3
+ class Piston::Git::TestGitWorkingCopyRememberance < Piston::TestCase
4
+ def setup
5
+ super
6
+ @wcdir = mkpath("tmp/wc")
7
+ Dir.chdir(@wcdir) { git(:init) }
8
+ @wc = Piston::Git::WorkingCopy.new(@wcdir)
9
+ end
10
+
11
+ def test_creates_dot_piston_dot_yml_file
12
+ @wc.remember({}, "a" => "b")
13
+ assert((@wcdir + ".piston.yml").exist?)
14
+ end
15
+
16
+ def test_writes_values_as_yaml_under_handler_key
17
+ expected = {"a" => "b"}
18
+ @wc.remember({}, expected)
19
+ actual = YAML.load((@wcdir + ".piston.yml").read)
20
+ assert_equal expected, actual["handler"]
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../test_helper")
2
+
3
+ class Piston::Svn::TestSvnRepositoryAt < Piston::TestCase
4
+ def setup
5
+ super
6
+ @repos = Piston::Svn::Repository.new("http://bla.com/svn/repos/trunk")
7
+ end
8
+
9
+ def test_instantiate_revision_at_head
10
+ Piston::Svn::Revision.expects(:new).with(@repos, "HEAD").returns(:newrev)
11
+ assert_equal :newrev, @repos.at(:head)
12
+ end
13
+
14
+ def test_instantiate_revision_using_recalled_values
15
+ recalled_values = {Piston::Svn::REMOTE_REV => 9123, Piston::Svn::UUID => "5ecf4fe2-1ee6-0310-87b1-e25e094e27de"}
16
+ Piston::Svn::Revision.expects(:new).with(@repos, 9123, recalled_values).returns(:newrev)
17
+ assert_equal :newrev, @repos.at(recalled_values)
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../test_helper")
2
+
3
+ class Piston::Svn::TestSvnRepositoryBasename < Piston::TestCase
4
+ def test_basename_is_urls_path_last_component
5
+ assert_equal "piston", basename("http://svn.rubyforge.org/var/svn/piston")
6
+ end
7
+
8
+ def test_basename_is_urls_path_last_component_minus_trunk
9
+ assert_equal "attachment_fu", basename("svn+ssh://some.host.com/svn/attachment_fu/trunk")
10
+ end
11
+
12
+ def test_basename_is_urls_path_last_component_before_branches
13
+ assert_equal "rails", basename("svn://some.host.com/svn/rails/branches/stable")
14
+ end
15
+
16
+ def test_basename_is_urls_path_last_component_before_tags
17
+ assert_equal "plugin", basename("https://some.host.com/svn/plugin/tags/stable")
18
+ end
19
+
20
+ private
21
+ def basename(url)
22
+ Piston::Svn::Repository.new(url).basename
23
+ end
24
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../test_helper")
2
+
3
+ class Piston::Svn::TestSvnRepositoryGuessing < Piston::TestCase
4
+ def test_guesses_with_svn_protocol
5
+ assert Piston::Svn::Repository.understands_url?("svn://a.host.com/")
6
+ end
7
+
8
+ def test_guesses_with_svn_plus_bla_protocol
9
+ assert Piston::Svn::Repository.understands_url?("svn+bla://username@a.host.com/")
10
+ end
11
+
12
+ def test_guesses_with_svn_plus_ssh_protocol
13
+ assert Piston::Svn::Repository.understands_url?("svn+ssh://username@a.host.com/")
14
+ end
15
+
16
+ def test_contacts_repository_for_file_protocol
17
+ url = "file:///home/username/svn/projects/trunk"
18
+ Piston::Svn::Repository.expects(:svn).with(:info, url).returns("Repository UUID: abcdef\n")
19
+ assert Piston::Svn::Repository.understands_url?(url)
20
+ end
21
+
22
+ def test_contacts_repository_for_http_protocol
23
+ url = "http://svn.collab.net/repos/svn/trunk"
24
+ Piston::Svn::Repository.expects(:svn).with(:info, url).returns("Repository UUID: abcdef\n")
25
+ assert Piston::Svn::Repository.understands_url?(url)
26
+ end
27
+
28
+ def test_contacts_repository_for_https_protocol
29
+ url = "https://svn.collab.net/repos/svn/trunk"
30
+ Piston::Svn::Repository.expects(:svn).with(:info, url).returns("Repository UUID: abcdef\n")
31
+ assert Piston::Svn::Repository.understands_url?(url)
32
+ end
33
+
34
+ def test_says_does_not_understand_when_svn_info_errors_out
35
+ url = "http://rubyonrails.org/"
36
+ Piston::Svn::Repository.expects(:svn).with(:info, url).raises(Piston::Svn::Client::Failed)
37
+ deny Piston::Svn::Repository.understands_url?(url)
38
+ end
39
+
40
+ def test_says_does_not_understand_when_svn_command_not_found
41
+ url = "http://rubyonrails.org/"
42
+ Piston::Svn::Repository.expects(:svn).with(:info, url).raises(Piston::Svn::Client::BadCommand)
43
+ deny Piston::Svn::Repository.understands_url?(url)
44
+ end
45
+ end
@@ -0,0 +1,28 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../test_helper")
2
+
3
+ class Piston::Svn::TestSvnRevisionCheckout < Piston::TestCase
4
+ def setup
5
+ super
6
+ @wcdir = Pathname.new("tmp/wc")
7
+ @repos = mock("repository")
8
+ @repos.stubs(:url).returns("http://a.repos.com/trunk")
9
+ end
10
+
11
+ def test_head_checkout_to_path
12
+ rev = new_revision("HEAD")
13
+ rev.expects(:svn).with(:checkout, "--revision", "HEAD", @repos.url, @wcdir).returns("Checked out revision 1322.")
14
+ rev.checkout_to(@wcdir)
15
+ assert_equal 1322, rev.revision
16
+ end
17
+
18
+ def test_specific_revision_checkout_to_path
19
+ rev = new_revision(1231)
20
+ rev.expects(:svn).with(:checkout, "--revision", 1231, @repos.url, @wcdir).returns("Checked out revision 1231.")
21
+ rev.checkout_to(@wcdir)
22
+ end
23
+
24
+ private
25
+ def new_revision(revision)
26
+ Piston::Svn::Revision.new(@repos, revision)
27
+ end
28
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../test_helper")
2
+
3
+ class Piston::Svn::TestSvnRevisionEach < Piston::TestCase
4
+ def setup
5
+ super
6
+ @repos = mock("repository")
7
+ @repos.stubs(:url).returns("http://a.repos.com/project/trunk")
8
+
9
+ @wcdir = Pathname.new("tmp/.wc.tmp")
10
+
11
+ @rev = Piston::Svn::Revision.new(@repos, "HEAD")
12
+ @rev.stubs(:svn).returns("Checked out revision 111.\n")
13
+ @rev.checkout_to(@wcdir)
14
+ end
15
+
16
+ def test_each_skips_over_svn_metadata_folders
17
+ @rev.expects(:svn).with(:ls, "--recursive", @wcdir).returns("CONTRIBUTORS\nREADME\ntest/test_helper.rb\n")
18
+ expected = ["CONTRIBUTORS", "README", "test/test_helper.rb"]
19
+ actual = @rev.inject([]) {|memo, relpath| memo << relpath}
20
+ assert_equal expected.sort, actual.sort
21
+ end
22
+ end
@@ -0,0 +1,38 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../test_helper")
2
+
3
+ class Piston::Svn::TestSvnRevisionRememberance < Piston::TestCase
4
+ def setup
5
+ super
6
+ @wcdir = mkpath("tmp/wc")
7
+ @repos = mock("repository")
8
+ @repos.stubs(:url).returns("http://a.repos.com/svn/trunk")
9
+
10
+ @info = {"Path" => @wcdir.realpath,
11
+ "URL" => "http://a.repos.com/svn/trunk",
12
+ "Repository Root" => "http://a.repos.com/svn",
13
+ "Repository UUID" => "some-long-uuid",
14
+ "Revision" => "9283",
15
+ "Node Kind" => "directory",
16
+ "Schedule" => "normal",
17
+ "Last Changed Author" => "me",
18
+ "Last Changed Rev" => "9283",
19
+ "Last Changed Date" => "2008-03-11 20:44:24 -0400 (Tue, 11 Mar 2008)"}
20
+ end
21
+
22
+ def test_remembers_repos_uuid
23
+ rev = new_revision("HEAD")
24
+ rev.expects(:svn).with(:info, "--revision", "HEAD", @repos.url).returns(@info.to_yaml)
25
+ assert_equal "some-long-uuid", rev.remember_values[Piston::Svn::UUID]
26
+ end
27
+
28
+ def test_remembers_repos_revision
29
+ rev = new_revision("HEAD")
30
+ rev.expects(:svn).with(:info, "--revision", "HEAD", @repos.url).returns(@info.to_yaml)
31
+ assert_equal "9283", rev.remember_values[Piston::Svn::REMOTE_REV]
32
+ end
33
+
34
+ private
35
+ def new_revision(revision)
36
+ Piston::Svn::Revision.new(@repos, revision)
37
+ end
38
+ end