Skip to content

Commit

Permalink
Fix overriding existing symlinks that point to directories.
Browse files Browse the repository at this point in the history
  • Loading branch information
wjbuys committed Aug 23, 2011
1 parent fa99a89 commit 9ced292
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/homesick.rb
Expand Up @@ -79,6 +79,7 @@ def pull(name="")
end

desc "symlink NAME", "Symlinks all dotfiles from the specified castle"
method_option :force, :default => false, :desc => "Overwrite existing conflicting symlinks without prompting."
def symlink(name)
check_castle_existance(name, "symlink")

Expand Down
2 changes: 1 addition & 1 deletion lib/homesick/actions.rb
Expand Up @@ -86,7 +86,7 @@ def ln_s(source, destination, config = {})
say_status :conflict, "#{destination} exists and points to #{destination.readlink}", :red unless options[:quiet]

if options[:force] || shell.file_collision(destination) { source }
system "ln -sf #{source} #{destination}" unless options[:pretend]
system "ln -nsf #{source} #{destination}" unless options[:pretend]
end
end
elsif destination.exist?
Expand Down
16 changes: 16 additions & 0 deletions spec/homesick_spec.rb
Expand Up @@ -7,6 +7,7 @@
let(:castles) { home.directory(".homesick/repos") }

let(:homesick) { Homesick.new }

before { homesick.stub!(:repos_dir).and_return(castles) }

describe "clone" do
Expand Down Expand Up @@ -104,6 +105,21 @@
home.join("bin").readlink.should == dotfile
end

context "when forced" do
let(:homesick) { Homesick.new [], :force => true }

it "can override symlinks to directories" do
somewhere_else = create_construct
existing_dotdir_link = home.join(".vim")
FileUtils.ln_s somewhere_else, existing_dotdir_link

dotdir = castle.directory(".vim")

homesick.symlink("glencairn")

existing_dotdir_link.readlink.should == dotdir
end
end
end

describe "list" do
Expand Down

0 comments on commit 9ced292

Please sign in to comment.