namespace :deploy do

desc <<-DESC
    Copy files to the currently deployed version. This is useful for updating \
    files piecemeal, such as when you need to quickly deploy only a single \
    file. Some files, such as updated templates, images, or stylesheets, \
    might not require a full deploy, and especially in emergency situations \
    it can be handy to just push the updates to production, quickly.

    To use this task, specify the files and directories you want to copy as a \
    comma-delimited list in the FILES environment variable. All directories \
    will be processed recursively, with all files being pushed to the \
    deployment servers.

      $ cap staging deploy:upload FILES=templates,controller.rb

    Dir globs are also supported:

      $ cap staging deploy:upload FILES='config/apache/*.conf'
DESC
task :upload do
  files = (ENV["FILES"] || "").split(",").map { |f| Dir[f.strip] }.flatten
  abort "Please specify at least one file or directory to update (via the FILES environment variable)" if files.empty?

  on release_roles :all do
    files.each { |file| upload!(file, File.join(current_path, file)) }
  end

  invoke "deploy:restart"
end

end