Commit a0ecd74a6f41cc10d634c41d594af17f0d4b133d

New switch command specs.

git-svn-id: svn+ssh://rubyforge.org/var/svn/piston/trunk@109 d6c2ea82-c31b-0410-8381-e9c44f9824c5

Commit diff

lib/piston/commands/switch.rb

 
3636 local_revision = local_revision.succ
3737
3838 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']
4040
4141 logging_stream.puts " Fetching remote repository's latest revision and UUID"
4242 info = YAML::load(svn(:info, "#{repos}@#{remote_revision}"))
4343 return skip(dir, "Repository UUID changed\n Expected #{uuid}\n Found #{info['Repository UUID']}\n Repository: #{repos}") unless uuid == info['Repository UUID']
4444
4545 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
4846 revisions = (remote_revision .. (revision || new_remote_rev))
4947
5048 logging_stream.puts " Restoring remote repository to known state at r#{revisions.first}"
toggle raw diff

specs/switch_spec.rb

 
1require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
2require "piston"
3require "piston/command"
4require "piston/commands/import"
5
6context "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
73end
toggle raw diff