mirror of
https://github.com/tj/git-extras.git
synced 2026-09-10 07:26:17 -04:00
Add a new -f/--force option to git-clear to allow usage in scripts, or without user input. Add -h/--help/? for help Also update the manual for git-clear for these changes.
44 lines
786 B
Bash
Executable file
44 lines
786 B
Bash
Executable file
#!/usr/bin/env bash
|
|
PROGNAME="git-clear"
|
|
FORCE=0
|
|
|
|
function _usage() {
|
|
cat << EOF
|
|
usage: $PROGNAME options
|
|
usage: $PROGNAME -h|help|?
|
|
|
|
clear git repository
|
|
|
|
OPTIONS:
|
|
-f, --force Force clear without questioning user
|
|
-h, --help, ? Show this message
|
|
EOF
|
|
}
|
|
|
|
# Read arguments
|
|
while [ "$1" != "" ]; do
|
|
case $1 in
|
|
-f|--force)
|
|
FORCE=1
|
|
;;
|
|
-h|--help|?)
|
|
_usage
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
shift
|
|
done
|
|
|
|
# Only wait for answer if not forced by user
|
|
if [[ $FORCE == 0 ]]; then
|
|
echo -n "Sure? - This command may delete files that cannot be recovered, including those in .gitignore [y/N]: "
|
|
read clean
|
|
else
|
|
clean=y
|
|
fi
|
|
|
|
if [ "$clean" == "y" ]; then
|
|
git clean -d -f -x && git reset --hard
|
|
fi
|