Rake任务取决于其他rake任务

时间:2015-07-27 16:17:58

标签: ruby rake

我有rake任务,为Git提供功能。我希望能够致电rake git:pull,它应该认识到目录@source_dir不存在,然后在尝试git:clone之前会调用git:pull。可以在我的任务中添加这样的依赖项吗?

namespace :git do
  desc "Download and create a copy of code from git server"
  task :clone do
    puts 'Cloning repository'.pink
    sh "git clone -b #{@git_branch} --single-branch #{@git_clone_url} #{@source_dir}"
    puts 'Clone complete'.green
  end

  desc "Fetch and merge from git server, using current checked out branch"
  task :pull do
    puts 'Pulling git'.pink
    sh "cd '#{@source_dir}'; git pull"
    puts 'Pulled'.green
  end

  desc "Shows status of all files in git repo"
  task :status do
    puts 'Showing `git status` of all source files'.pink
    sh "cd #{@source_dir} && git status --short"
  end
end

1 个答案:

答案 0 :(得分:2)

通常你只需声明这样的依赖:

task :pull => :clone do
  # ...
end

或者在多个依赖项的情况下:

task :status => [ :clone, :pull ] do
  # ...
end
相关问题