Skip to content

Commit ae1cea9

Browse files
committed
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.
1 parent 916b6aa commit ae1cea9

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/thor/actions/create_link.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class CreateLink < CreateFile #:nodoc:
3333
# Boolean:: true if it is identical, false otherwise.
3434
#
3535
def identical?
36-
exists? && File.identical?(render, destination)
36+
source = File.expand_path(render, File.dirname(destination))
37+
exists? && File.identical?(source, destination)
3738
end
3839

3940
def invoke!

spec/actions/create_link_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ def revoke!
9393
invoke!
9494
expect(action.identical?).to be true
9595
end
96+
97+
context "with source path relative to destination" do
98+
let(:source) do
99+
destination_path = File.dirname(File.join(destination_root, destination))
100+
Pathname.new(super()).relative_path_from(Pathname.new(destination_path)).to_s
101+
end
102+
103+
it "returns true if the destination link exists and is identical" do
104+
expect(action.identical?).to be false
105+
invoke!
106+
expect(action.identical?).to be true
107+
end
96108
end
97109
end
98110

0 commit comments

Comments
 (0)