Skip to content

Instantly share code, notes, and snippets.

@sefk
Last active August 29, 2015 13:56
Show Gist options
  • Save sefk/9243749 to your computer and use it in GitHub Desktop.
Save sefk/9243749 to your computer and use it in GitHub Desktop.
#!/bin/bash -e
#
# WARNING: THIS SCRIPT IS DESTRUCTIVE. IT WILL DELETE THINGS IN YOUR
# ACTUAL REPO. ONLY USE IF YOU KNOW WHAT YOU ARE DOING.
#
# This script saves away a small number of files, and then removes all
# other files in your repo, to leave it in a pristine state. This is
# useful if there are artifacts in your build tree (.js, .pyc) that are
# causing trouble.
#
# This script is intended to be run as a post-checkout hook. You can
# add to a git repo by putting in .git/hooks/post-checkout.
#
# (c) 2014 Sef Kloninger
#
# files relative to base of base of repo
files_to_preserve=(
lms/envs/private.py
cms/envs/private.py
.pycharm_helpers
django
)
myname=$(basename $0)
repodir=$(git rev-parse --show-toplevel)
savedir=$(mktemp -d -t sefsave)
# save
for devfile in ${files_to_preserve[*]}; do
[[ ! -e $devfile ]] && continue
echo "$myname: saving $devfile"
savefile=$savedir/$devfile
mkdir -p $(dirname $savefile)
mv $devfile $savefile
done
# clean
git clean -xdf
# restore
cd $savedir
for savefile in $(find -P . -type f); do
echo "$myname: restoring $savefile"
devfile=$repodir/$savefile
mkdir -p $repodir/$(dirname $savefile)
mv $savefile $devfile
done
rm -r $savedir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment