Skip to content

Instantly share code, notes, and snippets.

@itskingori
Created March 2, 2016 15:15
Show Gist options
  • Save itskingori/51332a1471be1db96b22 to your computer and use it in GitHub Desktop.
Save itskingori/51332a1471be1db96b22 to your computer and use it in GitHub Desktop.
Bundler: Bump 1 gem and touch nothing else with bundle-unlock
#!/usr/bin/env ruby
#
# Updating a gem normally leads to it's dependencies being updates as well.
# This script only removes the gem itself from the lockfile, allowing to update it without
# touching anything else.
#
# bundle-unlock foobar && bundle
# Source: https://github.com/grosser/dotfiles/blob/master/bin/bundle-unlock
raise 'Give me the gems' if ARGV.empty?
lockfile = (ENV['BUNDLE_GEMFILE'] || 'Gemfile') << '.lock'
content = File.read(lockfile)
ARGV.each do |gem|
content.sub!(/^ #{Regexp.escape(gem)} .*\n( \S.*\n)*/, '') || raise("missing 4-space indent for #{gem}")
content.sub!(/^ #{Regexp.escape(gem)}(\n| .*\n)( \S.*\n)*/, '') || raise("missing 2-space indent for #{gem}")
end
File.write(lockfile, content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment