我有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
答案 0 :(得分:2)
通常你只需声明这样的依赖:
task :pull => :clone do
# ...
end
或者在多个依赖项的情况下:
task :status => [ :clone, :pull ] do
# ...
end