Skip to content

Instantly share code, notes, and snippets.

@michaelglass
Last active May 11, 2018 16:13
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 michaelglass/9471b9288c3e71e64384f25b8345cdba to your computer and use it in GitHub Desktop.
Save michaelglass/9471b9288c3e71e64384f25b8345cdba to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# usage: invalidate-old-elm "src directories space delimeted" BRANCH_TO_COMPARE OPTIONAL_BRANCH_TO_COMPARE_DEFAULTS_TO_HEAD
# git diff --name-only gives us relative paths from git root
# git rev-parse --show-prefix this fetches the current directory's relative prefix to the git root
# we remove the prefix
prefix=$(git rev-parse --show-prefix)
for file in $(git diff --name-only $2 $3 | grep .elm$)
# collect changed files and select only elms
do
relative_path=$(printf $file | sed -e "s|$prefix||")
for src_dir in $1
do
src_dir=$src_dir/
if [[ $relative_path == $src_dir* ]]; then
# remove the src_dir to find in elm-stuff
elm=$(printf $relative_path | sed -e "s|$src_dir||")
elmi=$(printf $elm | tr "/" "-")i
find elm-stuff/build-artifacts -type f -name $elmi -exec rm {} \;
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment