Created
March 23, 2012 15:51
-
-
Save vjt/2172051 to your computer and use it in GitHub Desktop.
Rome RSC 2012-03: Develop application and dependent gems, tricking bundler
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 | |
if ARGV[0] == ARGV[1] && $0 =~ /git.*hook/ # Not switching branches | |
exit 0 | |
end | |
require 'rubygems' | |
require 'bundler' | |
require 'pathname' | |
root = Pathname(Dir.getwd) | |
lock = root.join('Gemfile.lock').read | |
Bundler::LockfileParser.new(lock).sources.each do |source| | |
next unless source.respond_to? :uri | |
# If you want to filter on something | |
#next unless source.uri =~ /vjt\// | |
$stdout.print "[#{source.uri}] " | |
$stdout.flush | |
rev = source.send(:revision) | |
dir = source.uri.scan(/\/([\w_-]+)\.git$/).first.first | |
dir = root.join('..', dir) | |
Dir.chdir dir | |
symbolic_ref = %x{ git describe --all #{rev} } | |
symbolic_ref.sub! /^heads\//, '' | |
%x{ git checkout #{symbolic_ref} } | |
%x{ symlink-gem #{dir} } | |
end |
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
#!/bin/bash | |
geminstall=`gem environment gemdir` | |
if [ -z "$geminstall" ]; then | |
echo 'Cannot find gem installation directory' | |
exit -1 | |
fi | |
gem=$1 | |
if [ -z "$gem" ]; then | |
echo "Usage: $0 <gemdir>" | |
exit 1 | |
fi | |
if [ ! -d "$gem" ]; then | |
echo "Gem $gem not exist" | |
exit 2 | |
fi | |
cd $gem | |
dir=`pwd` | |
name=`basename $dir` | |
if [ ! -d "$dir/.git" ]; then | |
echo "$dir is not a Git repository checkout" | |
exit 3 | |
fi | |
ref=`git describe 2>/dev/null` | |
ref=`git rev-parse --short=12 ${ref:=HEAD}` | |
cd $geminstall/bundler/gems | |
rm -rf $name-* | |
ln -s $dir $name-$ref |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment