Created
March 2, 2016 15:15
-
-
Save itskingori/51332a1471be1db96b22 to your computer and use it in GitHub Desktop.
Bundler: Bump 1 gem and touch nothing else with bundle-unlock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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