Skip to content

Commit 371f2a3

Browse files
committed
Fix #587
1 parent 1ec3eff commit 371f2a3

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

lib/thor/actions/file_manipulation.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ def copy_file(source, *args, &block)
2323
destination = args.first || source
2424
source = File.expand_path(find_in_source_paths(source.to_s))
2525

26-
create_file destination, nil, config do
26+
resulting_destination = create_file destination, nil, config do
2727
content = File.binread(source)
2828
content = yield(content) if block
2929
content
3030
end
3131
if config[:mode] == :preserve
3232
mode = File.stat(source).mode
33-
chmod(destination, mode, config)
33+
chmod(resulting_destination, mode, config)
3434
end
3535
end
3636

spec/actions/file_manipulation_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ def file
7676
expect(File.stat(original).mode).to eq(File.stat(copy).mode)
7777
end
7878

79+
it "copies file from source to default destination and preserves file mode for templated filenames" do
80+
expect(runner).to receive(:filename).and_return("app")
81+
action :copy_file, "preserve/%filename%.sh", :mode => :preserve
82+
original = File.join(source_root, "preserve/%filename%.sh")
83+
copy = File.join(destination_root, "preserve/app.sh")
84+
expect(File.stat(original).mode).to eq(File.stat(copy).mode)
85+
end
86+
7987
it "logs status" do
8088
expect(action(:copy_file, "command.thor")).to eq(" create command.thor\n")
8189
end

spec/fixtures/preserve/%filename%.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
exit 0

0 commit comments

Comments
 (0)