| |   |
| 11 | 11 | raise Piston::UnknownRepository, @repos.url unless @repos.exists? |
| 12 | 12 | |
| 13 | 13 | @wc = Piston::WorkingCopy.new(@path, :logger => options[:logger]) |
| 14 | | @root = @wc.parent |
| 14 | @root = @wc.up |
| 15 | 15 | raise Piston::LocalChangesPending.new(@root.dir) unless @root.status(true).grep(/#{@wc.path}/).empty? |
| 16 | 16 | end |
| 17 | 17 | |
| 18 | 18 | def run |
| 19 | | @wc.export(@repos.url) |
| 19 | @revision = @options[:revision] || @repos.youngest |
| 20 | @wc.export(@repos.url, @revision) |
| 20 | 21 | @root.add(@wc.path) |
| 22 | |
| 23 | @wc.propset(Piston::REMOTE_ROOT, @repos.url) |
| 21 | 24 | @wc.propset(Piston::REMOTE_UUID, @repos.uuid) |
| 22 | | @wc.propset(Piston::REMOTE_REVISION, @repos.youngest) |
| 25 | @wc.propset(Piston::REMOTE_REVISION, @revision) |
| 23 | 26 | @wc.propset(Piston::LOCAL_REVISION, @wc.last_changed_revision || 0) |
| 27 | @wc.propset(Piston::LOCKED, "*") if @options[:lock] |
| 24 | 28 | end |
| 25 | 29 | |
| 26 | 30 | def debug(&block) |
| toggle raw diff |
--- a/lib/piston/commands/import.rb
+++ b/lib/piston/commands/import.rb
@@ -11,16 +11,20 @@ module Piston
raise Piston::UnknownRepository, @repos.url unless @repos.exists?
@wc = Piston::WorkingCopy.new(@path, :logger => options[:logger])
- @root = @wc.parent
+ @root = @wc.up
raise Piston::LocalChangesPending.new(@root.dir) unless @root.status(true).grep(/#{@wc.path}/).empty?
end
def run
- @wc.export(@repos.url)
+ @revision = @options[:revision] || @repos.youngest
+ @wc.export(@repos.url, @revision)
@root.add(@wc.path)
+
+ @wc.propset(Piston::REMOTE_ROOT, @repos.url)
@wc.propset(Piston::REMOTE_UUID, @repos.uuid)
- @wc.propset(Piston::REMOTE_REVISION, @repos.youngest)
+ @wc.propset(Piston::REMOTE_REVISION, @revision)
@wc.propset(Piston::LOCAL_REVISION, @wc.last_changed_revision || 0)
+ @wc.propset(Piston::LOCKED, "*") if @options[:lock]
end
def debug(&block) |
| |   |
| 28 | 28 | @wc.propget(Piston::REMOTE_UUID, "vendor").should == @upstream.uuid |
| 29 | 29 | end |
| 30 | 30 | |
| 31 | it "should have copied the upstream repository's URL as a property on the import path" do |
| 32 | @wc.propget(Piston::REMOTE_ROOT, "vendor").should == @upstream.url |
| 33 | end |
| 34 | |
| 31 | 35 | it "should have copied the upstream revision as a property on the import path" do |
| 32 | 36 | @wc.propget(Piston::REMOTE_REVISION, "vendor").should == @upstream.youngest |
| 33 | 37 | end |
| … | … | |
| 104 | 104 | raise_error(Piston::UnknownRepository) |
| 105 | 105 | end |
| 106 | 106 | end |
| 107 | |
| 108 | describe Piston::Commands::Import, "#run(upstream_url, 'vendor/', :lock => true)" do |
| 109 | it_should_behave_like "An upstream repository with no copies/renames" |
| 110 | |
| 111 | before do |
| 112 | @repos = Piston::Repository.new("file://" + self.tmppath(:repos)).create! |
| 113 | @wc = Piston::WorkingCopy.new(self.tmppath(:wc)) |
| 114 | @wc.checkout(@repos.url) |
| 115 | |
| 116 | Piston::Commands::Import.new(@upstream.url, @wc.path + "vendor", :logger => self.logger, :lock => true).run |
| 117 | end |
| 118 | |
| 119 | it "should have locked the folder" do |
| 120 | @wc.propget(Piston::LOCKED, "vendor").should == "*" |
| 121 | end |
| 122 | end |
| 123 | |
| 124 | describe Piston::Commands::Import, "#run(upstream_url, 'vendor/', :revision => 1)" do |
| 125 | it_should_behave_like "An upstream repository with no copies/renames" |
| 126 | |
| 127 | before do |
| 128 | @repos = Piston::Repository.new("file://" + self.tmppath(:repos)).create! |
| 129 | @wc = Piston::WorkingCopy.new(self.tmppath(:wc)) |
| 130 | @wc.checkout(@repos.url) |
| 131 | |
| 132 | Piston::Commands::Import.new(@upstream.url, @wc.path + "vendor", :logger => self.logger, :revision => 1).run |
| 133 | @wc = @wc.down("vendor") |
| 134 | end |
| 135 | |
| 136 | it "should have exported revision 1" do |
| 137 | lambda { @wc.cat("LICENSE") }.should raise_error(Piston::WorkingCopy::FileNotFound) |
| 138 | end |
| 139 | |
| 140 | it "should remember the remote revision was 1, not HEAD" do |
| 141 | @wc.propget(Piston::REMOTE_REVISION).should == 1 |
| 142 | end |
| 143 | end |
| 144 | |
| 145 | describe Piston::Commands::Import, "#run(upstream_url, 'vendor/', :revision => 2, :lock => true)" do |
| 146 | it_should_behave_like "An upstream repository with no copies/renames" |
| 147 | |
| 148 | before do |
| 149 | @repos = Piston::Repository.new("file://" + self.tmppath(:repos)).create! |
| 150 | @wc = Piston::WorkingCopy.new(self.tmppath(:wc)) |
| 151 | @wc.checkout(@repos.url) |
| 152 | |
| 153 | Piston::Commands::Import.new(@upstream.url, @wc.path + "vendor", :logger => self.logger, :revision => 2, :lock => true).run |
| 154 | @wc = @wc.down("vendor") |
| 155 | end |
| 156 | |
| 157 | it "should have exported revision 2" do |
| 158 | lambda { @wc.cat("LICENSE") }.should_not raise_error(Piston::WorkingCopy::FileNotFound) |
| 159 | lambda { @wc.cat("README") }.should raise_error(Piston::WorkingCopy::FileNotFound) |
| 160 | end |
| 161 | |
| 162 | it "should have locked the folder" do |
| 163 | @wc.propget(Piston::LOCKED).should == "*" |
| 164 | end |
| 165 | |
| 166 | it "should remember the remote revision was 2, not HEAD" do |
| 167 | @wc.propget(Piston::REMOTE_REVISION).should == 2 |
| 168 | end |
| 169 | end |
| toggle raw diff |
--- a/spec/import_spec.rb
+++ b/spec/import_spec.rb
@@ -28,6 +28,10 @@ describe Piston::Commands::Import, "#run(upstream_url, 'vendor/')" 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
@@ -100,3 +104,66 @@ describe Piston::Commands::Import, "#run(non_existent_url, 'vendor/')" do
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
|