File: git-clear

package info (click to toggle)
git-extras 7.4.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 2,120 kB
  • sloc: sh: 4,312; python: 994; makefile: 146
file content (43 lines) | stat: -rwxr-xr-x 779 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env bash
PROGNAME="git-clear"
FORCE=0

_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 -r clean
else
    clean=y
fi

if [ "$clean" = "y" ]; then
    git clean -d -f -x && git reset --hard
fi