Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "file clash" bug #541

Merged
merged 2 commits into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/thor/actions/empty_directory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,17 @@ def invoke_with_conflict_check(&block)
if exists?
on_conflict_behavior(&block)
else
say_status :create, :green
yield unless pretend?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this was changed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If say_status is before yield, in case of a conflict we have a misleading message. For instance:

create  doc/config/config.rb
file_clash  doc/config/config.rb

say_status :create, :green
end

destination
rescue Errno::EISDIR, Errno::EEXIST
on_file_clash_behavior
end

def on_file_clash_behavior
say_status :file_clash, :red
end

# What to do when the destination file already exists.
Expand Down
24 changes: 24 additions & 0 deletions spec/actions/create_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,30 @@ def silence!
end
end
end

context "when file exists and it causes a file clash" do
before do
create_file("doc/config")
invoke!
end

it "generates a file clash" do
create_file("doc/config/config.rb")
expect(invoke!).to eq(" file_clash doc/config/config.rb\n")
end
end

context "when directory exists and it causes a file clash" do
before do
create_file("doc/config/hello")
invoke!
end

it "generates a file clash" do
create_file("doc/config")
expect(invoke!) .to eq(" file_clash doc/config\n")
end
end
end

describe "#revoke!" do
Expand Down