@@ -73,7 +73,7 @@ module Homesick
|
|||||||
when :conflict
|
when :conflict
|
||||||
say_status :conflict, "#{destination} exists", :red
|
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.rm_r destination, force: true unless options[:pretend]
|
||||||
FileUtils.ln_s source, destination, force: true unless options[:pretend]
|
FileUtils.ln_s source, destination, force: true unless options[:pretend]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -25,10 +25,13 @@ module Homesick
|
|||||||
exit(1)
|
exit(1)
|
||||||
end
|
end
|
||||||
# Hack in support for diffing symlinks
|
# 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 = class << shell; self; end
|
||||||
shell_metaclass.send(:define_method, :show_diff) do |destination, content|
|
shell_metaclass.send(:define_method, :show_diff) do |destination, content|
|
||||||
destination = Pathname.new(destination)
|
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 "- #{destination.readlink}", :red, true
|
||||||
say "+ #{content.expand_path}", :green, true
|
say "+ #{content.expand_path}", :green, true
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -148,8 +148,8 @@ module Homesick
|
|||||||
first_p.mtime > second_p.mtime && !first_p.symlink?
|
first_p.mtime > second_p.mtime && !first_p.symlink?
|
||||||
end
|
end
|
||||||
|
|
||||||
def collision_accepted?(destination)
|
def collision_accepted?(destination, source)
|
||||||
fail "Argument must be an instance of Pathname, #{destination.class.name} given" unless destination.instance_of?(Pathname)
|
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 }
|
options[:force] || shell.file_collision(destination) { source }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user