From ab39c090e41f6cf78da82e83d036a82ff40439bf Mon Sep 17 00:00:00 2001 From: Chris Andreae Date: Mon, 16 Dec 2019 15:42:33 +0900 Subject: [PATCH] Handle relative source path in create_link #identical? When creating a symlink, the source path may be relative to the destination. If this is the case, #identical? fails becase it interprets it as an absolute path. Update #identical to resolve the source path before comparing. --- lib/thor/actions/create_link.rb | 3 ++- spec/actions/create_link_spec.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/thor/actions/create_link.rb b/lib/thor/actions/create_link.rb index 51d4dab82..3c6014279 100644 --- a/lib/thor/actions/create_link.rb +++ b/lib/thor/actions/create_link.rb @@ -33,7 +33,8 @@ class CreateLink < CreateFile #:nodoc: # Boolean:: true if it is identical, false otherwise. # def identical? - exists? && File.identical?(render, destination) + source = File.expand_path(render, File.dirname(destination)) + exists? && File.identical?(source, destination) end def invoke! diff --git a/spec/actions/create_link_spec.rb b/spec/actions/create_link_spec.rb index 4d17c0ba9..75657d382 100644 --- a/spec/actions/create_link_spec.rb +++ b/spec/actions/create_link_spec.rb @@ -93,6 +93,18 @@ def revoke! invoke! expect(action.identical?).to be true end + + context "with source path relative to destination" do + let(:source) do + destination_path = File.dirname(File.join(destination_root, destination)) + Pathname.new(super()).relative_path_from(destination_path).to_s + end + + it "returns true if the destination link exists and is identical" do + expect(action.identical?).to be false + invoke! + expect(action.identical?).to be true + end end end