Skip to content

Commit cb4a1d9

Browse files
authored
Merge pull request #541 from nodo/fix-file-clash
Fix "file clash" bug
2 parents 593effe + ab0cdfe commit cb4a1d9

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/thor/actions/empty_directory.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,17 @@ def invoke_with_conflict_check(&block)
114114
if exists?
115115
on_conflict_behavior(&block)
116116
else
117-
say_status :create, :green
118117
yield unless pretend?
118+
say_status :create, :green
119119
end
120120

121121
destination
122+
rescue Errno::EISDIR, Errno::EEXIST
123+
on_file_clash_behavior
124+
end
125+
126+
def on_file_clash_behavior
127+
say_status :file_clash, :red
122128
end
123129

124130
# What to do when the destination file already exists.

spec/actions/create_file_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,30 @@ def silence!
131131
end
132132
end
133133
end
134+
135+
context "when file exists and it causes a file clash" do
136+
before do
137+
create_file("doc/config")
138+
invoke!
139+
end
140+
141+
it "generates a file clash" do
142+
create_file("doc/config/config.rb")
143+
expect(invoke!).to eq(" file_clash doc/config/config.rb\n")
144+
end
145+
end
146+
147+
context "when directory exists and it causes a file clash" do
148+
before do
149+
create_file("doc/config/hello")
150+
invoke!
151+
end
152+
153+
it "generates a file clash" do
154+
create_file("doc/config")
155+
expect(invoke!) .to eq(" file_clash doc/config\n")
156+
end
157+
end
134158
end
135159

136160
describe "#revoke!" do

0 commit comments

Comments
 (0)