diff --git a/lib/homesick/actions/file_actions.rb b/lib/homesick/actions/file_actions.rb index 27e77f7..255010a 100644 --- a/lib/homesick/actions/file_actions.rb +++ b/lib/homesick/actions/file_actions.rb @@ -73,7 +73,7 @@ module Homesick when :conflict say_status :conflict, "#{destination} exists", :red - if collision_accepted?(destination) + if collision_accepted?(destination, source) FileUtils.rm_r destination, force: true unless options[:pretend] FileUtils.ln_s source, destination, force: true unless options[:pretend] end diff --git a/lib/homesick/cli.rb b/lib/homesick/cli.rb index 89dbf56..c82f34a 100644 --- a/lib/homesick/cli.rb +++ b/lib/homesick/cli.rb @@ -25,10 +25,13 @@ module Homesick exit(1) end # Hack in support for diffing symlinks + # Also adds support for checking if destination or content is a directory shell_metaclass = class << shell; self; end shell_metaclass.send(:define_method, :show_diff) do |destination, content| destination = Pathname.new(destination) - return super unless destination.symlink? + content = Pathname.new(content) + return 'Unable to create diff: destination or content is a directory' if destination.directory? || content.directory? + return super(destination, content) unless destination.symlink? say "- #{destination.readlink}", :red, true say "+ #{content.expand_path}", :green, true end diff --git a/lib/homesick/utils.rb b/lib/homesick/utils.rb index 1afe266..435224f 100644 --- a/lib/homesick/utils.rb +++ b/lib/homesick/utils.rb @@ -148,8 +148,8 @@ module Homesick first_p.mtime > second_p.mtime && !first_p.symlink? end - def collision_accepted?(destination) - fail "Argument must be an instance of Pathname, #{destination.class.name} given" unless destination.instance_of?(Pathname) + def collision_accepted?(destination, source) + fail "Arguments must be instances of Pathname, #{destination.class.name} and #{source.class.name} given" unless destination.instance_of?(Pathname) && source.instance_of?(Pathname) options[:force] || shell.file_collision(destination) { source } end