Skip to content

Instantly share code, notes, and snippets.

@neilk
Last active July 11, 2017 21:07
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 neilk/acbcbf83670a29f2937dc487e6677609 to your computer and use it in GitHub Desktop.
Save neilk/acbcbf83670a29f2937dc487e6677609 to your computer and use it in GitHub Desktop.
In a Scala/SBT project, figure out what dependencies are added or removed in a branch
#!/bin/bash
# Find dependency changes in a branch in a scala project using sbt.
# You have to have the https://github.com/jrudolph/sbt-dependency-graph plugin installed.
# the standard `sed` on Mac OS X won't work, so make sure to install GNU sed via brew.
branch="$1"
function is_git_clean() {
[[ $(git status 2> /dev/null | tail -n1) =~ "nothing to commit" ]]
}
if ! is_git_clean; then
echo "your git repo has changes. Commit them first";
exit 1;
fi
git checkout master
sbt dependencyList > /tmp/deps-master
git checkout "$branch" # your branch
sbt dependencyList > /tmp/deps-branch
# sbt outputs ANSI colors, always. Strip them away
gsed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" /tmp/deps-master > /tmp/deps-master-plain
gsed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" /tmp/deps-branch > /tmp/deps-branch-plain
# get just the package names
perl -wlne '/([\w-]+(\.[\w-]+)*:)+\d+(\.\d+)+/ and print $&' /tmp/deps-master-plain | sort | uniq > /tmp/deps-master-plain-uniq
perl -wlne '/([\w-]+(\.[\w-]+)*:)+\d+(\.\d+)+/ and print $&' /tmp/deps-branch-plain | sort | uniq > /tmp/deps-branch-plain-uniq
# and diff them
diff /tmp/deps-{master,branch}-plain-uniq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment