Skip to content

Commit

Permalink
Merge pull request #1189 from Kriechi/do-not-overwrite
Browse files Browse the repository at this point in the history
Don't overwrite existing config files
  • Loading branch information
leehambley committed Nov 17, 2014
2 parents 7335208 + b1e83f7 commit d546af2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Breaking Changes:
* Cucumber scenario improvements (@bruno-)
* Added suggestion to Capfile to use 'capistrano-passenger' gem, replacing suggestion in config/deploy.rb to re-implement 'deploy:restart' (@betesh)
* Updated svn fetch_revision method to use `svnversion`
* `cap install` no longer overwrites existing files. (@dmarkow)

## `3.2.1`

Expand Down
31 changes: 17 additions & 14 deletions lib/capistrano/tasks/install.rake
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,28 @@ task :install do

mkdir_p deploy_dir

template = File.read(deploy_rb)
file = config_dir.join('deploy.rb')
File.open(file, 'w+') do |f|
f.write(ERB.new(template).result(binding))
puts I18n.t(:written_file, scope: :capistrano, file: file)
end

template = File.read(stage_rb)
envs.split(',').each do |stage|
file = deploy_dir.join("#{stage}.rb")
File.open(file, 'w+') do |f|
f.write(ERB.new(template).result(binding))
puts I18n.t(:written_file, scope: :capistrano, file: file)
entries = [{template: deploy_rb, file: config_dir.join('deploy.rb')}]
entries += envs.split(',').map { |stage| {template: stage_rb, file: deploy_dir.join("#{stage}.rb")} }

entries.each do |entry|
if File.exists?(entry[:file])
warn "[skip] #{entry[:file]} already exists"
else
File.open(entry[:file], 'w+') do |f|
f.write(ERB.new(File.read(entry[:template])).result(binding))
puts I18n.t(:written_file, scope: :capistrano, file: entry[:file])
end
end
end

mkdir_p tasks_dir

FileUtils.cp(capfile, 'Capfile')
if File.exists?('Capfile')
warn "[skip] Capfile already exists"
else
FileUtils.cp(capfile, 'Capfile')
puts I18n.t(:written_file, scope: :capistrano, file: 'Capfile')
end


puts I18n.t :capified, scope: :capistrano
Expand Down

0 comments on commit d546af2

Please sign in to comment.