def apply_staleness_check(commands)
needs(:deploy_to, :repository)
check = "cd #{self[:deploy_to]}; " +
"ml=\`cat .git/refs/heads/#{branch}\`; " +
"mr=\`git ls-remote #{self[:repository]} refs/heads/#{branch}\`; "
if self[:deploy_config_to]
check += "cd #{self[:deploy_config_to]}; " +
"cl=\`cat .git/refs/heads/#{config_branch}\`; " +
"cr=\`git ls-remote #{self[:config_repository]} refs/heads/#{config_branch}\`; "
end
check += "if [[ $ml != ${mr%%\t*} ]] " +
(self[:deploy_config_to] ? "|| [[ $cl != ${cr%%\t*} ]]" : '') +
"; then #{commands}; else echo \"No changes to deploy.\"; fi"
end