Fix overriding existing symlinks that point to directories.
This commit is contained in:
@@ -79,6 +79,7 @@ class Homesick < Thor
|
|||||||
end
|
end
|
||||||
|
|
||||||
desc "symlink NAME", "Symlinks all dotfiles from the specified castle"
|
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)
|
def symlink(name)
|
||||||
check_castle_existance(name, "symlink")
|
check_castle_existance(name, "symlink")
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ class Homesick
|
|||||||
say_status :conflict, "#{destination} exists and points to #{destination.readlink}", :red unless options[:quiet]
|
say_status :conflict, "#{destination} exists and points to #{destination.readlink}", :red unless options[:quiet]
|
||||||
|
|
||||||
if options[:force] || shell.file_collision(destination) { source }
|
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
|
||||||
end
|
end
|
||||||
elsif destination.exist?
|
elsif destination.exist?
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ describe "homesick" do
|
|||||||
let(:castles) { home.directory(".homesick/repos") }
|
let(:castles) { home.directory(".homesick/repos") }
|
||||||
|
|
||||||
let(:homesick) { Homesick.new }
|
let(:homesick) { Homesick.new }
|
||||||
|
|
||||||
before { homesick.stub!(:repos_dir).and_return(castles) }
|
before { homesick.stub!(:repos_dir).and_return(castles) }
|
||||||
|
|
||||||
describe "clone" do
|
describe "clone" do
|
||||||
@@ -104,6 +105,21 @@ describe "homesick" do
|
|||||||
home.join("bin").readlink.should == dotfile
|
home.join("bin").readlink.should == dotfile
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "list" do
|
describe "list" do
|
||||||
|
|||||||
Reference in New Issue
Block a user