Skip to content

Instantly share code, notes, and snippets.

@erochest
Created November 7, 2012 18:48
Show Gist options
  • Save erochest/4033576 to your computer and use it in GitHub Desktop.
Save erochest/4033576 to your computer and use it in GitHub Desktop.
abusing blocks
def update_subm(name, &block)
puts "Updating submodules for '#{name}'...."
if block.nil?
sh %{cd #{name} ; #{GIT_SM_UP}}
else
sh %{cd #{name} ; #{GIT_SM_UP}} do |o, r|
block.call(o, r)
end
end
end
desc 'This does a recursive git submodule update.'
task :update do
update_subm '.' do |ok, res|
puts "ERROR: #{ok}. #{res}. Continuing."
end
sh %{cd #{GEOEXPLORER_DIR}/app/static/externals/gxp/externals/TimeManager ; git reset --hard HEAD}
end
@erochest
Copy link
Author

erochest commented Nov 7, 2012

Basically, I'm trying to eat the error that the first shell state in the task throws. To do that, I want to define a block on the calling location, but just pass it untouched to the call to sh.

Originally, I'd been calling update_subm multiple times, so having it refactored into its own method made more sense.

I assume that what I'm doing here can't be right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment