I have rake tasks which provide functionality for Git. I would like to be able to call rake git:pull
which should recognize that the directory @source_dir
does not exist and then it will call git:clone
before attempting git:pull
. It is possible to add such a dependency to my tasks?
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
Typically you just declare dependencies like this:
task :pull => :clone do
# ...
end
Or in the case of multiple dependencies:
task :status => [ :clone, :pull ] do
# ...
end