Migrate git-quiltimport.sh to use git-rev-parse --parseopt
[git/dscho.git] / git-clean.sh
blob35a5142c56f8d6f9007fcde840bf0d90b1d02a3a
1 #!/bin/sh
3 # Copyright (c) 2005-2006 Pavel Roskin
6 OPTIONS_KEEPDASHDASH=
7 OPTIONS_SPEC="\
8 git-clean [options] <paths>...
10 Clean untracked files from the working directory
12 When optional <paths>... arguments are given, the paths
13 affected are further limited to those that match them.
15 d remove directories as well
16 f override clean.requireForce and clean anyway
17 n don't remove anything, just show what would be done
18 q be quiet, only report errors
19 x remove ignored files as well
20 X remove only ignored files"
22 SUBDIRECTORY_OK=Yes
23 . git-sh-setup
24 require_work_tree
26 ignored=
27 ignoredonly=
28 cleandir=
29 disabled="`git config --bool clean.requireForce`"
30 rmf="rm -f --"
31 rmrf="rm -rf --"
32 rm_refuse="echo Not removing"
33 echo1="echo"
35 while test $# != 0
37 case "$1" in
38 -d)
39 cleandir=1
41 -f)
42 disabled=
44 -n)
45 disabled=
46 rmf="echo Would remove"
47 rmrf="echo Would remove"
48 rm_refuse="echo Would not remove"
49 echo1=":"
51 -q)
52 echo1=":"
54 -x)
55 ignored=1
57 -X)
58 ignoredonly=1
60 --)
61 shift
62 break
65 usage # should not happen
67 esac
68 shift
69 done
71 if [ "$disabled" = true ]; then
72 die "clean.requireForce set and -n or -f not given; refusing to clean"
75 if [ "$ignored,$ignoredonly" = "1,1" ]; then
76 die "-x and -X cannot be set together"
79 if [ -z "$ignored" ]; then
80 excl="--exclude-per-directory=.gitignore"
81 if [ -f "$GIT_DIR/info/exclude" ]; then
82 excl_info="--exclude-from=$GIT_DIR/info/exclude"
84 if [ "$ignoredonly" ]; then
85 excl="$excl --ignored"
89 git ls-files --others --directory $excl ${excl_info:+"$excl_info"} -- "$@" |
90 while read -r file; do
91 if [ -d "$file" -a ! -L "$file" ]; then
92 if [ -z "$cleandir" ]; then
93 $rm_refuse "$file"
94 continue
96 $echo1 "Removing $file"
97 $rmrf "$file"
98 else
99 $echo1 "Removing $file"
100 $rmf "$file"
102 done