require File.dirname(__FILE__) + "/spec_helper" require "piston/commands/import" require "piston/commands/update" describe Piston::Commands::Update, "#run" do it_should_behave_like "An upstream repository with no copies/renames" it "should find all pistonized folders and update them in turn" end describe Piston::Commands::Update, "#run('vendor')" do it_should_behave_like "An upstream repository with no copies/renames" it_should_behave_like "A working copy against a local repository" before do Piston::Commands::Import.new(@upstream.url, @wc.wc_path("vendor"), :revision => 1, :logger => logger).run @wc.commit "Pistonized vendor@r1" @vendor = @wc.down("vendor") @command = Piston::Commands::Update.new(@wc.wc_path("vendor"), :logger => logger) end after do @wc.destroy! end it "should receive new folders" do @upwc.mkdir("lib") @upwc.create!("lib/calc.c", "int calc() { /* TBD */ }") @upwc.commit @command.run status = @wc.status.map {|st| st.sub(@wc.path, "")} status.sort.should == [ " M /vendor", "A /vendor/lib", "A /vendor/lib/calc.c", "A /vendor/LICENSE", "A /vendor/README", "M /vendor/main.c", "M /vendor/CHANGELOG"].sort end end describe Piston::Commands::Update, "#run('vendor')" do it_should_behave_like "An upstream repository with no copies/renames" it_should_behave_like "A working copy against a local repository" before do Piston::Commands::Import.new(@upstream.url, @wc.wc_path("vendor"), :revision => 1, :logger => logger).run @wc.commit "Pistonized vendor@r1" @vendor = @wc.down("vendor") @command = Piston::Commands::Update.new(@wc.wc_path("vendor"), :logger => logger) end after do @wc.destroy! end it "should delete deleted files" do @upwc.delete("CHANGELOG") @upwc.commit @command.run status = @wc.status.map {|st| st.sub(@wc.path, "")} status.should include("D /vendor/CHANGELOG") end end describe Piston::Commands::Update, "#run('vendor')" do it_should_behave_like "An upstream repository with no copies/renames" it_should_behave_like "A working copy against a local repository" before do Piston::Commands::Import.new(@upstream.url, @wc.wc_path("vendor"), :revision => 1, :logger => logger).run @wc.commit "Pistonized vendor@r1" @vendor = @wc.down("vendor") @command = Piston::Commands::Update.new(@wc.wc_path("vendor"), :logger => logger) end after do @wc.destroy! end it "should move files" do @upwc.move("CHANGELOG", "Changelog.txt") @upwc.commit @command.run status = @wc.status.map {|st| st.sub(@wc.path, "")} status.should include("D /vendor/CHANGELOG") status.should include("A + /vendor/Changelog.txt") end end describe Piston::Commands::Update, "#run('vendor')" do it_should_behave_like "An upstream repository with no copies/renames" it_should_behave_like "A working copy against a local repository" before do Piston::Commands::Import.new(@upstream.url, @wc.wc_path("vendor"), :revision => 1, :logger => logger).run @wc.commit "Pistonized vendor@r1" @vendor = @wc.down("vendor") @command = Piston::Commands::Update.new(@wc.wc_path("vendor"), :logger => logger) end after do @wc.destroy! end it "should copy files" do @upwc.copy("CHANGELOG", "old-changelog.txt") @upwc.commit @command.run status = @wc.status.map {|st| st.sub(@wc.path, "")} status.should include("A + /vendor/old-changelog.txt") end end describe Piston::Commands::Update, "#run('vendor')" do it_should_behave_like "An upstream repository with no copies/renames" it_should_behave_like "A working copy against a local repository" before do Piston::Commands::Import.new(@upstream.url, @wc.wc_path("vendor"), :revision => 1, :logger => logger).run @wc.commit "Pistonized vendor@r1" @vendor = @wc.down("vendor") @command = Piston::Commands::Update.new(@wc.wc_path("vendor"), :logger => logger) end after do @wc.destroy! end it "should reject the update if the repository UUID is not as expected" do @vendor.propset(Piston::REMOTE_UUID, "some-random-string") lambda { @command.run }.should raise_error(Piston::RepositoryUuidChanged) end it "should reject the update when the repository is gone" do @upstream.destroy! lambda { @command.run }.should raise_error(Piston::UnknownRepository) end end describe Piston::Commands::Update, "#run('vendor')" do it_should_behave_like "An upstream repository with no copies/renames" it_should_behave_like "A working copy against a local repository" before do Piston::Commands::Import.new(@upstream.url, @wc.wc_path("vendor"), :revision => 1, :logger => logger).run @wc.commit "Pistonized vendor@r1" @vendor = @wc.down("vendor") @command = Piston::Commands::Update.new(@wc.wc_path("vendor"), :logger => logger) @command.run end after do @wc.destroy! end it "should receive vendor's HEAD changes" do status = @wc.status status.map! do |st| st.sub(@wc.path, "") end status.sort.should == [ " M /vendor", "A /vendor/LICENSE", "A /vendor/README", "M /vendor/main.c", "M /vendor/CHANGELOG"].sort end it "should record new vendor's HEAD" do @vendor.propget(Piston::REMOTE_REVISION).to_i.should == @upstream.youngest end it "should record new local HEAD (unchanged, since no changes in local repos)" do @vendor.propget(Piston::LOCAL_REVISION).to_i.should == 0 end end describe Piston::Commands::Update, "#run('vendor') when local modifications have been made" do it_should_behave_like "An upstream repository with no copies/renames" it_should_behave_like "A working copy against a local repository" before do Piston::Commands::Import.new(@upstream.url, @wc.wc_path("vendor"), :revision => 1, :logger => logger).run @wc.commit "Pistonized vendor@r1" @vendor = @wc.down("vendor") @vendor.edit!("main.c", < int main(int argc, char** argv) { return 0; } EOF ) @vendor.commit @vendor.update @command = Piston::Commands::Update.new(@wc.wc_path("vendor"), :logger => logger) @command.run end it "should record new local HEAD" do @vendor.propget(Piston::LOCAL_REVISION).to_i.should == 2 end it "should merge local modifications" do File.read(@vendor.wc_path("main.c")).should == < /** Main program file */ int main(int argc, char** argv) { return do_work(argc); } int do_work(int argc) { return 2*argc; } EOF end end