xwords/xwords4/android/scripts/rm-non-git.sh

55 lines
1.3 KiB
Bash
Raw Normal View History

#!/bin/bash
set -u -e
EXCEPTS=" "
2016-07-18 17:49:36 +02:00
DRY_RUN=''
usage() {
[ $# -ge 1 ] && echo "ERROR: $1"
2016-07-18 17:49:36 +02:00
echo "usage: $0 [--dry-run] [--except path/to/file]*"
echo " Starting in current directory, recursively remove all non-git-controlled"
echo " files, excepting those named with --except flags."
exit 1
}
while [ $# -ge 1 ]; do
case $1 in
--except)
FILE=$2
shift
if [ $FILE != ${FILE#/} ]; then # starts with / ?
2014-11-21 03:57:57 +01:00
: # leave it alone
elif [ "$FILE" != "${FILE#\./}" ]; then # starts with ./ ?
: # leave it alone
else
FILE="./${FILE}" # prepend ./ to match ls output
fi
EXCEPTS=" $EXCEPTS $FILE "
;;
2016-07-18 17:49:36 +02:00
--dry-run)
DRY_RUN=1
;;
--help)
usage
;;
*)
usage "unexpected param $1"
;;
esac
shift
done
2016-07-18 17:49:36 +02:00
for FILE in $(find $(pwd) -type f); do
if [ ! "${EXCEPTS}" = "${EXCEPTS# $FILE }" ]; then
continue
elif git ls-files $FILE --error-unmatch 2>/dev/null 1>/dev/null; then
continue
else
echo "$FILE not under git; removing..."
[ -n "$DRY_RUN" ] || rm $FILE
fi
done
2016-07-18 17:49:36 +02:00
echo "$0: done" >&2