--pretty=format: on-demand format expansion
[git/mingw.git] / git-clean.sh
blobf4965b8391436384bf795c1e39b7f9158e624e51
1 #!/bin/sh
3 # Copyright (c) 2005-2006 Pavel Roskin
6 USAGE="[-d] [-f] [-n] [-q] [-x | -X] [--] <paths>..."
7 LONG_USAGE='Clean untracked files from the working directory
8 -d remove directories as well
9 -f override clean.requireForce and clean anyway
10 -n don'\''t remove anything, just show what would be done
11 -q be quiet, only report errors
12 -x remove ignored files as well
13 -X remove only ignored files
14 When optional <paths>... arguments are given, the paths
15 affected are further limited to those that match them.'
16 SUBDIRECTORY_OK=Yes
17 . git-sh-setup
18 require_work_tree
20 ignored=
21 ignoredonly=
22 cleandir=
23 rmf="rm -f --"
24 rmrf="rm -rf --"
25 rm_refuse="echo Not removing"
26 echo1="echo"
28 # requireForce used to default to false but now it defaults to true.
29 # IOW, lack of explicit "clean.requireForce = false" is taken as
30 # "clean.requireForce = true".
31 disabled=$(git config --bool clean.requireForce || echo true)
33 while test $# != 0
35 case "$1" in
36 -d)
37 cleandir=1
39 -f)
40 disabled=
42 -n)
43 disabled=
44 rmf="echo Would remove"
45 rmrf="echo Would remove"
46 rm_refuse="echo Would not remove"
47 echo1=":"
49 -q)
50 echo1=":"
52 -x)
53 ignored=1
55 -X)
56 ignoredonly=1
58 --)
59 shift
60 break
62 -*)
63 usage
66 break
67 esac
68 shift
69 done
71 if [ "$disabled" = true ]; then
72 echo "clean.requireForce set and -n or -f not given; refusing to clean"
73 exit 1
76 case "$ignored,$ignoredonly" in
77 1,1) usage;;
78 esac
80 if [ -z "$ignored" ]; then
81 excl="--exclude-per-directory=.gitignore"
82 if [ -f "$GIT_DIR/info/exclude" ]; then
83 excl_info="--exclude-from=$GIT_DIR/info/exclude"
85 if [ "$ignoredonly" ]; then
86 excl="$excl --ignored"
90 git ls-files --others --directory $excl ${excl_info:+"$excl_info"} -- "$@" |
91 while read -r file; do
92 if [ -d "$file" -a ! -L "$file" ]; then
93 if [ -z "$cleandir" ]; then
94 $rm_refuse "$file"
95 continue
97 $echo1 "Removing $file"
98 $rmrf "$file"
99 else
100 $echo1 "Removing $file"
101 $rmf "$file"
103 done