require File.dirname(__FILE__) + "/spec_helper" require "piston/working_copy" require "piston/repository" require "fileutils" describe Piston::WorkingCopy do it_should_behave_like "A working copy against a local repository" before do @wc.export(@repos.url) end it "should export itself" do File.directory?(File.join(@wc.dir)).should == true end it "should NOT be a Subversion working copy" do File.directory?(File.join(@wc.dir, ".svn")).should == false end end describe Piston::WorkingCopy, "#log" do it_should_behave_like "A working copy against a local repository" before do @wc.checkout(@repos.url) @wc.create!("main.c", "") @wc.commit @wc.edit!("main.c", "one line") @wc.commit @wc.delete("main.c") @wc.commit @wc.create!("main.c", "") @wc.commit @wc.copy("main.c", "calc.c") @wc.commit @wc.move("calc.c", "libcalc.c") @wc.commit end it "should report adding main.c in r1" do @wc.log(1).should == [[:add, "main.c"]] end it "should report modifying main.c in r2" do @wc.log(2).should == [[:modify, "main.c"]] end it "should report deleting main.c in r3" do @wc.log(3).should == [[:delete, "main.c"]] end it "should report copying main.c to calc.c in r5" do @wc.log(5).should == [[:copy, {"main.c" => "calc.c"}]] end it "should report moving calc.c to libcalc.c in r6" do @wc.log(6).should == [[:move, {"calc.c" => "libcalc.c"}]] end it "should report only an add for A+M in revision range" do @wc.log(0..2).should == [[:add, "main.c"]] end it "should report only a delete from M+D in revision range" do @wc.log(1..3).should == [[:delete, "main.c"]] end it "should report only a delete from A+M+D in revision range" do @wc.log(0..3).should == [[:delete, "main.c"]] end it "should report only a delete from A+M+D in revision range" do @wc.log(4..6).should == [[:add, "main.c"], [:copy, {"main.c"=>"calc.c"}], [:move, {"calc.c"=>"libcalc.c"}]] end it "should report paths relative to the current working copy, not absolute from the repository's root" end describe Piston::WorkingCopy do it_should_behave_like "A working copy against a local repository" before do @wc.checkout(@repos.url) end it "should checkout itself" do File.directory?(@wc_dir).should == true end it "should be a Subversion working copy" do File.directory?(File.join(@wc_dir, ".svn")).should == true end it "should report the same UUID as the repository's" do @wc.uuid.should == @repos.uuid end it "should report the same Repository URL as the repository's" do @wc.url.should == @repos.url end it "should report this working copy's revision" do @wc.revision.should == 0 end it "should report the last changed revision" do @wc.last_changed_revision.should == 0 end it "should allow setting a property" do @wc.propset "ranger", "bla" `svn proplist --verbose #{@wc.dir}`.should =~ /^\s\sranger\s:\sbla$/ end it "should allow adding a new file" do File.open(File.join(@wc.dir, "CHANGES"), "wb") {|f| f.puts "some text content"} @wc.add "CHANGES" `svn status #{@wc.dir}`.should =~ %r|^A #{@wc.dir}/CHANGES$| end it "should allow committing changes" do File.open(File.join(@wc.dir, "CHANGES"), "wb") {|f| f.puts "some text content"} @wc.add "CHANGES" @wc.commit("Adding CHANGES").should == 1 end it "should allow creating a new directory" do @wc.mkdir "trunk" `svn status #{@wc.path}`.should =~ /^A #{@wc.path + "trunk"}/ end end describe Piston::WorkingCopy, "with properties on the root WC dir" do it_should_behave_like "A working copy against a local repository" before do @wc.checkout @repos.url @wc.propset "piston:long", "a long value with\nnewlines and all." @wc.propset "piston:short", "short" end it "should allow reading the short property and return 'short' as the value" do @wc.propget("piston:short").should == "short" end it "should allow reading the long property and return the full value" do @wc.propget("piston:long").should == "a long value with\nnewlines and all." end it "should allow reading all properties in one go" do @wc.properties.should == {"piston:long" => "a long value with\nnewlines and all.", "piston:short" => "short"} end it "should alias propget to []" do @wc["piston:short"].should == "short" end it "should alias propset to []=" do @wc["piston:temp"] = "new value" @wc.propget("piston:temp").should == "new value" end it "should return a Fixnum when the property value is an Integer" do @wc.propset "piston:some-property", 24 @wc.propget("piston:some-property").should == 24 end it "should return nil when the property doesn't exist" do @wc.propget("piston:some-property").should be_nil end end describe Piston::WorkingCopy, "against a repository with 1 revision" do it_should_behave_like "A working copy against a local repository" before do @wc.checkout @repos.url File.open(File.join(@wc.dir, "main.c"), "wb") {|f| f.puts "int main(int argc, char** argv) {\n return 0;\n\n}"} @wc.add "main.c" @wc.commit @wc.destroy! end it "should be able to checkout r0" do @wc.checkout(@repos.url, 0) File.exist?(@wc.dir + "/main.c").should == false end it "should be able to export r0" do @wc.export(@repos.url, 0) File.exist?(@wc.dir + "/main.c").should == false end end describe Piston::WorkingCopy, "at revision 1" do it_should_behave_like "A working copy against a local repository" before do @wc.checkout @repos.url @wc.create!("main.c", "int main(int argc, char** argv) {\n return 0;\n\n}") @wc.commit end it "should return the new revision number when updating" do @wc.update.should == 1 end it "should update to a specific revision" do @wc.update 0 (@wc.path + "main.c").should_not exist end it "should report local status as unchanged when no local changes" do @wc.status.should == [] end it "should report the remote status as unchanged when at HEAD and no local changes" do @wc.status(true).should == [] end it "should report file to be added when at r0" do @wc.update 0 @wc.status(true).should == [ " * #{@wc.dir}/main.c", " * 0 #{@wc.dir}" ] end it "should allow copying main.c to main2.c" do @wc.copy("main.c", "main2.c") `svn status #{@wc.dir}`.should == <