require File.dirname(__FILE__) + "/spec_helper" require "piston/commands/import" describe Piston::Commands::Import, "#run(upstream_url, 'vendor/')" do it_should_behave_like "An upstream repository with no copies/renames" before do @repos = Piston::Repository.new("file://" + self.tmppath(:repos)).create! @wc = Piston::WorkingCopy.new(self.tmppath(:wc)) @wc.checkout(@repos.url) Piston::Commands::Import.new(@upstream.url, @wc.path + "vendor", :logger => self.logger).run end it "should create a vendor/ folder" do (@wc.path + "vendor").should exist end it "should export the HEAD version of main.c" do (@wc.path + "vendor/main.c").read.should == @upstream.cat("main.c") end it "should have added vendor/ to the working copy" do @wc.status.should include("A #{@wc.path + "vendor"}") end it "should have copied the upstream repository's UUID as a property on the import path" do @wc.propget(Piston::REMOTE_UUID, "vendor").should == @upstream.uuid end it "should have copied the upstream repository's URL as a property on the import path" do @wc.propget(Piston::REMOTE_ROOT, "vendor").should == @upstream.url end it "should have copied the upstream revision as a property on the import path" do @wc.propget(Piston::REMOTE_REVISION, "vendor").should == @upstream.youngest end it "should NOT have locked the folder" do @wc.propget(Piston::LOCKED, "vendor").should be_nil end it "should have copied the last changed revision of the local working copy as a property on the import path" do @wc.propget(Piston::LOCAL_REVISION, "vendor").should == 0 end end describe Piston::Commands::Import, "#run(upstream_url, 'vendor/') with pending changes" do it_should_behave_like "An upstream repository with no copies/renames" before do @repos = Piston::Repository.new("file://" + self.tmppath(:repos)).create! @wc = Piston::WorkingCopy.new(self.tmppath(:wc)) @wc.checkout(@repos.url) @wc.create!("CHANGELOG", "rev1") @wc.commit @wc.update(0) end it "should raise a LocalChangesPending exception when the import path has local changes" do @wc.mkdir "vendor" lambda { Piston::Commands::Import.new(@upstream.url, @wc.path + "vendor", :logger => self.logger) }.should \ raise_error(Piston::LocalChangesPending) end it "should raise a LocalChangesPending exception when the working copy is out of date" do @wc.mkdir "vendor" @wc.commit @wc.update(1) lambda { Piston::Commands::Import.new(@upstream.url, @wc.path + "vendor", :logger => self.logger) }.should \ raise_error(Piston::LocalChangesPending) end end describe Piston::Commands::Import, "#run(upstream_url, 'vendor/') with an unrelated pending change" do it_should_behave_like "An upstream repository with no copies/renames" before do @repos = Piston::Repository.new("file://" + self.tmppath(:repos)).create! @wc = Piston::WorkingCopy.new(self.tmppath(:wc)) @wc.checkout(@repos.url) @wc.mkdir("app1") @wc.mkdir("app2") @wc.commit @wc.create!("app1/CHANGELOG", "rev1") @wc.commit @wc.update(1) end it "should raise no exception" do lambda { Piston::Commands::Import.new(@upstream.url, @wc.path + "app2", :logger => self.logger) }.should_not \ raise_error end end describe Piston::Commands::Import, "#run(non_existent_url, 'vendor/')" do include Piston::SpecHelpers it "should raise a Piston::UnknownRepository when the repository does not exist" do repos_path = "file://" + self.tmppath(:repos) wc_path = self.tmppath(:wc) lambda { Piston::Commands::Import.new(repos_path, wc_path + "vendor", :logger => self.logger) }.should \ raise_error(Piston::UnknownRepository) end end describe Piston::Commands::Import, "#run(upstream_url, 'vendor/', :lock => true)" do it_should_behave_like "An upstream repository with no copies/renames" before do @repos = Piston::Repository.new("file://" + self.tmppath(:repos)).create! @wc = Piston::WorkingCopy.new(self.tmppath(:wc)) @wc.checkout(@repos.url) Piston::Commands::Import.new(@upstream.url, @wc.path + "vendor", :logger => self.logger, :lock => true).run end it "should have locked the folder" do @wc.propget(Piston::LOCKED, "vendor").should == "*" end end describe Piston::Commands::Import, "#run(upstream_url, 'vendor/', :revision => 1)" do it_should_behave_like "An upstream repository with no copies/renames" before do @repos = Piston::Repository.new("file://" + self.tmppath(:repos)).create! @wc = Piston::WorkingCopy.new(self.tmppath(:wc)) @wc.checkout(@repos.url) Piston::Commands::Import.new(@upstream.url, @wc.path + "vendor", :logger => self.logger, :revision => 1).run @wc = @wc.down("vendor") end it "should have exported revision 1" do lambda { @wc.cat("LICENSE") }.should raise_error(Piston::WorkingCopy::FileNotFound) end it "should remember the remote revision was 1, not HEAD" do @wc.propget(Piston::REMOTE_REVISION).should == 1 end end describe Piston::Commands::Import, "#run(upstream_url, 'vendor/', :revision => 2, :lock => true)" do it_should_behave_like "An upstream repository with no copies/renames" before do @repos = Piston::Repository.new("file://" + self.tmppath(:repos)).create! @wc = Piston::WorkingCopy.new(self.tmppath(:wc)) @wc.checkout(@repos.url) Piston::Commands::Import.new(@upstream.url, @wc.path + "vendor", :logger => self.logger, :revision => 2, :lock => true).run @wc = @wc.down("vendor") end it "should have exported revision 2" do lambda { @wc.cat("LICENSE") }.should_not raise_error(Piston::WorkingCopy::FileNotFound) lambda { @wc.cat("README") }.should raise_error(Piston::WorkingCopy::FileNotFound) end it "should have locked the folder" do @wc.propget(Piston::LOCKED).should == "*" end it "should remember the remote revision was 2, not HEAD" do @wc.propget(Piston::REMOTE_REVISION).should == 2 end end