New switch command specs.
git-svn-id: svn+ssh://rubyforge.org/var/svn/piston/trunk@109 d6c2ea82-c31b-0410-8381-e9c44f9824c5
| |   |
| 36 | 36 | local_revision = local_revision.succ |
| 37 | 37 | |
| 38 | 38 | new_info = YAML::load(svn(:info, new_repos)) |
| 39 | | raise Piston::CommandError unless uuid == new_info['Repository UUID'] |
| 39 | raise Piston::CommandError, "Switching repositories is not supported at this time\nYou initially imported from #{uuid}, but are now importing from #{new_info['Repository UUID']}" unless uuid == new_info['Repository UUID'] |
| 40 | 40 | |
| 41 | 41 | logging_stream.puts " Fetching remote repository's latest revision and UUID" |
| 42 | 42 | info = YAML::load(svn(:info, "#{repos}@#{remote_revision}")) |
| 43 | 43 | return skip(dir, "Repository UUID changed\n Expected #{uuid}\n Found #{info['Repository UUID']}\n Repository: #{repos}") unless uuid == info['Repository UUID'] |
| 44 | 44 | |
| 45 | 45 | new_remote_rev = new_info['Last Changed Rev'].to_i |
| 46 | | return skip(dir, "unchanged from revision #{remote_revision}", false) if remote_revision == new_remote_rev |
| 47 | | |
| 48 | 46 | revisions = (remote_revision .. (revision || new_remote_rev)) |
| 49 | 47 | |
| 50 | 48 | logging_stream.puts " Restoring remote repository to known state at r#{revisions.first}" |
| toggle raw diff |
--- a/lib/piston/commands/switch.rb
+++ b/lib/piston/commands/switch.rb
@@ -36,15 +36,13 @@ module Piston
local_revision = local_revision.succ
new_info = YAML::load(svn(:info, new_repos))
- raise Piston::CommandError unless uuid == new_info['Repository UUID']
+ raise Piston::CommandError, "Switching repositories is not supported at this time\nYou initially imported from #{uuid}, but are now importing from #{new_info['Repository UUID']}" unless uuid == new_info['Repository UUID']
logging_stream.puts " Fetching remote repository's latest revision and UUID"
info = YAML::load(svn(:info, "#{repos}@#{remote_revision}"))
return skip(dir, "Repository UUID changed\n Expected #{uuid}\n Found #{info['Repository UUID']}\n Repository: #{repos}") unless uuid == info['Repository UUID']
new_remote_rev = new_info['Last Changed Rev'].to_i
- return skip(dir, "unchanged from revision #{remote_revision}", false) if remote_revision == new_remote_rev
-
revisions = (remote_revision .. (revision || new_remote_rev))
logging_stream.puts " Restoring remote repository to known state at r#{revisions.first}" |
| |   |
| 1 | require File.expand_path(File.dirname(__FILE__) + "/spec_helper") |
| 2 | require "piston" |
| 3 | require "piston/command" |
| 4 | require "piston/commands/import" |
| 5 | |
| 6 | context "switching to a branch in the same repository (without local mods)" do |
| 7 | include PistonCommandsHelper |
| 8 | |
| 9 | context_setup do |
| 10 | @remote_repos = Repository.new |
| 11 | @rwc = WorkingCopy.new(@remote_repos) |
| 12 | @rwc.checkout |
| 13 | @rwc.mkdir("/trunk") |
| 14 | |
| 15 | @rwc.add("/trunk/README", "this is line 1") |
| 16 | @rwc.commit |
| 17 | |
| 18 | @rwc.add("/trunk/main.c", "int main() { return 0; }") |
| 19 | @rwc.commit |
| 20 | |
| 21 | @rwc.mkdir("/branches") |
| 22 | @rwc.copy("/trunk", "/branches/stable") |
| 23 | @rwc.commit |
| 24 | |
| 25 | @rwc.change("/trunk/main.c", "int main() { /* trunk */ return 0; }") |
| 26 | @rwc.change("/branches/stable/main.c", "int main() { /* branch */ return 0; }") |
| 27 | @rwc.commit |
| 28 | |
| 29 | @local_repos = Repository.new |
| 30 | @lwc = WorkingCopy.new(@local_repos) |
| 31 | @lwc.checkout |
| 32 | |
| 33 | @lwc.propset("svn:externals", %Q(vendor #{@remote_repos.url + "/trunk"}), ".") |
| 34 | @lwc.commit |
| 35 | @lwc.update |
| 36 | |
| 37 | convert(@lwc.path) |
| 38 | @lwc.commit |
| 39 | @lwc.update |
| 40 | end |
| 41 | |
| 42 | setup do |
| 43 | switch(@remote_repos.url + "/branches/stable", @lwc.path + "/vendor") |
| 44 | end |
| 45 | |
| 46 | teardown do |
| 47 | @lwc.destroy |
| 48 | @lwc.checkout |
| 49 | end |
| 50 | |
| 51 | context_teardown do |
| 52 | @lwc.destroy |
| 53 | @local_repos.destroy |
| 54 | @rwc.destroy |
| 55 | @remote_repos.destroy |
| 56 | end |
| 57 | |
| 58 | specify "gets the fulltext of the branch" do |
| 59 | @lwc.cat("/vendor/main.c").should == "int main() { /* branch */ return 0; }" |
| 60 | end |
| 61 | |
| 62 | specify "changes the root of the pistoned dir to the new import location" do |
| 63 | @lwc.propget(Piston::ROOT, "vendor").should == @remote_repos.url + "/branches/stable" |
| 64 | end |
| 65 | |
| 66 | specify "keeps the upstream repository's UUID unchanged" do |
| 67 | @lwc.propget(Piston::UUID, "vendor").should == @remote_repos.uuid |
| 68 | end |
| 69 | |
| 70 | specify "remembers the upstream revision we pistoned from" do |
| 71 | @lwc.propget(Piston::REMOTE_REV, "vendor").should == "4" |
| 72 | end |
| 73 | end |
| toggle raw diff |
--- /dev/null
+++ b/specs/switch_spec.rb
@@ -0,0 +1,73 @@
+require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
+require "piston"
+require "piston/command"
+require "piston/commands/import"
+
+context "switching to a branch in the same repository (without local mods)" do
+ include PistonCommandsHelper
+
+ context_setup do
+ @remote_repos = Repository.new
+ @rwc = WorkingCopy.new(@remote_repos)
+ @rwc.checkout
+ @rwc.mkdir("/trunk")
+
+ @rwc.add("/trunk/README", "this is line 1")
+ @rwc.commit
+
+ @rwc.add("/trunk/main.c", "int main() { return 0; }")
+ @rwc.commit
+
+ @rwc.mkdir("/branches")
+ @rwc.copy("/trunk", "/branches/stable")
+ @rwc.commit
+
+ @rwc.change("/trunk/main.c", "int main() { /* trunk */ return 0; }")
+ @rwc.change("/branches/stable/main.c", "int main() { /* branch */ return 0; }")
+ @rwc.commit
+
+ @local_repos = Repository.new
+ @lwc = WorkingCopy.new(@local_repos)
+ @lwc.checkout
+
+ @lwc.propset("svn:externals", %Q(vendor #{@remote_repos.url + "/trunk"}), ".")
+ @lwc.commit
+ @lwc.update
+
+ convert(@lwc.path)
+ @lwc.commit
+ @lwc.update
+ end
+
+ setup do
+ switch(@remote_repos.url + "/branches/stable", @lwc.path + "/vendor")
+ end
+
+ teardown do
+ @lwc.destroy
+ @lwc.checkout
+ end
+
+ context_teardown do
+ @lwc.destroy
+ @local_repos.destroy
+ @rwc.destroy
+ @remote_repos.destroy
+ end
+
+ specify "gets the fulltext of the branch" do
+ @lwc.cat("/vendor/main.c").should == "int main() { /* branch */ return 0; }"
+ end
+
+ specify "changes the root of the pistoned dir to the new import location" do
+ @lwc.propget(Piston::ROOT, "vendor").should == @remote_repos.url + "/branches/stable"
+ end
+
+ specify "keeps the upstream repository's UUID unchanged" do
+ @lwc.propget(Piston::UUID, "vendor").should == @remote_repos.uuid
+ end
+
+ specify "remembers the upstream revision we pistoned from" do
+ @lwc.propget(Piston::REMOTE_REV, "vendor").should == "4"
+ end
+end
|