Don't try to symlink a castle to itself. Fixes #14

This commit is contained in:
Josh Nichols
2011-05-30 21:04:41 -04:00
parent 54697866f5
commit e19617be2f
2 changed files with 35 additions and 7 deletions

View File

@@ -21,7 +21,12 @@ class Homesick < Thor
inside repos_dir do inside repos_dir do
destination = nil destination = nil
if File.exist?(uri) if File.exist?(uri)
destination = Pathname.new(uri).basename uri = Pathname.new(uri).expand_path
if uri.to_s.start_with?(repos_dir)
raise "Castle already cloned to #{uri}"
end
destination = uri.basename
ln_s uri, destination ln_s uri, destination
elsif uri =~ GITHUB_NAME_REPO_PATTERN elsif uri =~ GITHUB_NAME_REPO_PATTERN

View File

@@ -6,14 +6,37 @@ describe "homesick" do
end end
describe "clone" do describe "clone" do
it "should symlink existing directories" do context "of a file" do
somewhere = create_construct it "should symlink existing directories" do
somewhere.directory('wtf') somewhere = create_construct
wtf = somewhere + 'wtf' somewhere.directory('wtf')
wtf = somewhere + 'wtf'
@homesick.should_receive(:ln_s).with(wtf.to_s, wtf.basename) @homesick.should_receive(:ln_s).with(wtf, wtf.basename)
@homesick.clone wtf.to_s @homesick.clone wtf
end
context "when it exists in a repo directory" do
before do
@repos_dir = create_construct
@existing_dir = @repos_dir.directory('existing_castle')
@homesick.stub!(:repos_dir).and_return(@repos_dir)
end
it "should not symlink" do
@homesick.should_not_receive(:git_clone)
@homesick.clone @existing_dir.to_s rescue nil
end
it "should raise an error" do
@existing_castle = @homesick.send(:repos_dir) + 'existing_castle'
lambda {
@homesick.clone @existing_castle.to_s
}.should raise_error(/already cloned/i)
end
end
end end
it "should clone git repo like git://host/path/to.git" do it "should clone git repo like git://host/path/to.git" do