Replace three `git sht` with the proper `git log --format=%h`
[sunny256-utils.git] / git-empty
blob4cb09275aa06039b6048b8c729a8f30c9e293f86
1 #!/bin/sh
3 #==============================================================================
4 # git-empty
5 # File ID: 40e83476-57e6-11e7-9426-db5caa6d21d3
7 # Delete all files from Git checkout to save space
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #==============================================================================
13 progname=git-empty
14 VERSION=0.2.1
16 opt_force=0
17 opt_help=0
18 opt_quiet=0
19 opt_verbose=0
20 while test -n "$1"; do
21 case "$1" in
22 -f|--force) opt_force=1; shift ;;
23 -h|--help) opt_help=1; shift ;;
24 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
25 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
26 --version) echo $progname $VERSION; exit 0 ;;
27 --) shift; break ;;
29 if printf '%s\n' "$1" | grep -q ^-; then
30 echo "$progname: $1: Unknown option" >&2
31 exit 1
32 else
33 break
35 break ;;
36 esac
37 done
38 opt_verbose=$(($opt_verbose - $opt_quiet))
40 if test "$opt_help" = "1"; then
41 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
42 cat <<END
44 Delete all versioned files and directories from a Git checkout to save
45 disk space. If any files are modified, it waits until the checkout is
46 clean before continuing. All files can be restored with "git checkout
47 -f".
49 Usage: $progname -f [options]
51 Options:
53 -f, --force
54 Actually delete the files. This option is mandatory to avoid
55 accidentally deleting the files, even though it's easy to get them
56 back.
57 -h, --help
58 Show this help.
59 -q, --quiet
60 Be more quiet. Can be repeated to increase silence.
61 -v, --verbose
62 Increase level of verbosity. Can be repeated.
63 --version
64 Print version information.
66 END
67 exit 0
70 if test "$opt_force" != "1"; then
71 echo $progname: -f/--force option not specified, aborting >&2
72 exit 1
75 git wait-until-clean -u || exit 1
76 git ls-files -z | xargs -0 --no-run-if-empty rm -f --
77 find . -depth -type d -print0 | \
78 grep -azv -e '/\.git/' | \
79 xargs -0 rmdir -- 2>/dev/null
81 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :