Documentation/user-manual.txt: fix typo
[git/haiku.git] / git-clean.sh
blob931d1aa4e4ed6cefb52c2dfe31aa5f059d0b2129
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 disabled="`git config --bool clean.requireForce`"
24 rmf="rm -f --"
25 rmrf="rm -rf --"
26 rm_refuse="echo Not removing"
27 echo1="echo"
29 while test $# != 0
31 case "$1" in
32 -d)
33 cleandir=1
35 -f)
36 disabled=
38 -n)
39 disabled=
40 rmf="echo Would remove"
41 rmrf="echo Would remove"
42 rm_refuse="echo Would not remove"
43 echo1=":"
45 -q)
46 echo1=":"
48 -x)
49 ignored=1
51 -X)
52 ignoredonly=1
54 --)
55 shift
56 break
58 -*)
59 usage
62 break
63 esac
64 shift
65 done
67 if [ "$disabled" = true ]; then
68 echo "clean.requireForce set and -n or -f not given; refusing to clean"
69 exit 1
72 case "$ignored,$ignoredonly" in
73 1,1) usage;;
74 esac
76 if [ -z "$ignored" ]; then
77 excl="--exclude-per-directory=.gitignore"
78 excl_info= excludes_file=
79 if [ -f "$GIT_DIR/info/exclude" ]; then
80 excl_info="--exclude-from=$GIT_DIR/info/exclude"
82 if cfg_excl=$(git config core.excludesfile) && test -f "$cfg_excl"
83 then
84 excludes_file="--exclude-from=$cfg_excl"
86 if [ "$ignoredonly" ]; then
87 excl="$excl --ignored"
91 git ls-files --others --directory \
92 $excl ${excl_info:+"$excl_info"} ${excludes_file:+"$excludes_file"} \
93 -- "$@" |
94 while read -r file; do
95 if [ -d "$file" -a ! -L "$file" ]; then
96 if [ -z "$cleandir" ]; then
97 $rm_refuse "$file"
98 continue
100 $echo1 "Removing $file"
101 $rmrf "$file"
102 else
103 $echo1 "Removing $file"
104 $rmf "$file"
106 done