1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

Merge pull request #1730 from troelskn/fix/emit-warning-when-invoke-is-used-on-a-task-that-has-already-been-invoked

Print a warning if a task is skipped because of re-invocation.
This commit is contained in:
Matt Brictson 2016-07-19 10:09:47 -07:00 committed by GitHub
commit bd2952bea8
3 changed files with 24 additions and 2 deletions

View file

@ -6,6 +6,7 @@ Reverse Chronological Order:
https://github.com/capistrano/capistrano/compare/v3.5.0...HEAD
* Added warning about future deprecation of reinvocation behaviour (@troelskn)
* Added a `doctor:servers` subtask that outputs a summary of servers, roles & properties (@irvingwashington)
* Raise a better error when an after hook isnt found (@jdelStrother)
* Restrict the uploaded git wrapper script permissions to 700 (@irvingwashington)

View file

@ -11,8 +11,18 @@ module Capistrano
include Paths
include Stages
def invoke(task, *args)
Rake::Task[task].invoke(*args)
def invoke(task_name, *args)
task = Rake::Task[task_name]
if task && task.already_invoked
file, line, = caller.first.split(":")
colors = SSHKit::Color.new($stderr)
$stderr.puts colors.colorize("Skipping task `#{task_name}'.", :yellow)
$stderr.puts "Capistrano tasks may only be invoked once. Since task `#{task}' was previously invoked, invoke(\"#{task_name}\") at #{file}:#{line} will be skipped."
$stderr.puts "If you really meant to run this task again, first call Rake::Task[\"#{task_name}\"].reenable"
$stderr.puts colors.colorize("THIS BEHAVIOR MAY CHANGE IN A FUTURE VERSION OF CAPISTRANO. Please join the conversation here if this affects you.", :red)
$stderr.puts colors.colorize("https://github.com/capistrano/capistrano/issues/1686", :red)
end
task.invoke(*args)
end
def t(key, options={})

View file

@ -69,5 +69,16 @@ module Capistrano
end
end
end
describe "#invoke" do
it "will print a message on stderr, when reinvoking task" do
Rake::Task.define_task("some_task")
dsl.invoke("some_task")
expect do
dsl.invoke("some_task")
end.to output(/.*Capistrano tasks may only be invoked once.*/).to_stderr
end
end
end
end