Skip to content

Instantly share code, notes, and snippets.

@mislav
Created October 29, 2014 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mislav/732b4ef52327b8aa2316 to your computer and use it in GitHub Desktop.
Save mislav/732b4ef52327b8aa2316 to your computer and use it in GitHub Desktop.
Script to diff contents of gems vendored in `vendor/cache` between branches
#!/bin/bash
# Usage: diff-gems <branch>
#
# Shows diff between unpacked cached gems that changed on a branch.
set -e
branch="${1?}"
base_branch="origin/master"
merge_base="$(git merge-base "$base_branch" "$branch")"
TMP="${TMPDIR:-/tmp}/diff-gems"
rm -rf "$TMP"
extract() {
local prefix="$1"
local where="$2"
local file="$3"
local gem_name="$(echo "${file##*/}" | sed -E 's/-[0-9].+//')"
local dest_dir="${TMP}/${prefix}/${gem_name}"
mkdir -p "$dest_dir"
git cat-file blob "${where}:${file}" | \
tar -xOf - --include '*.tar.gz' | \
tar xzf - -C "$dest_dir"
}
git diff "${base_branch}...${branch}" --name-status -- vendor/cache | \
while read mod gemfile; do
case "$mod" in
D ) extract "a" "$merge_base" "$gemfile" ;;
A ) extract "b" "$branch" "$gemfile" ;;
esac
done
cd "$TMP"
diff -u -r "a" "b" | {
if [ -t 1 ]; then
vim -R -
else
cat
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment