3 # Remove untracked files from the working tree
4 # Copyright (c) Pavel Roskin, 2005
6 # Cleans file and directories that are not under version control.
7 # When run without arguments, files ignored by `cg-status` and directories
12 # -d:: Clean directories
13 # Also clean directories and their contents.
15 # -D:: Clean directories more thoroughly
16 # Same as -d but try harder (change permissions first).
18 # -n:: Don't actually remove files, just pretend to
19 # Do not actually remove the files, just pretend to do so.
21 # -q:: Silence progress reporting
22 # Quiet - don't report what's being cleaned.
24 # -x:: Clean files ignored by cg-status
25 # Also clean files ignored by `cg-status`, such as object files.
27 # Testsuite: Complete (t9400-clean)
29 USAGE
="cg-clean [-d] [-D] [-n] [-q] [-x]"
31 .
"${COGITO_LIB}"cg-Xlib ||
exit 1
41 elif optparse
-D; then
44 elif optparse
-n; then
45 pretendrm
() { echo rm "$@"; }
47 elif optparse
-q; then
49 elif optparse
-x; then
56 [ ${#ARGS[*]} = 0 ] || usage
58 cd "${_git_relpath-.}"
59 list_untracked_files
"$noexclude" squashdirs |
tr '\0' '\n' |
60 while read -r file; do
61 if [ -d "$file" -a ! -L "$file" ]; then
62 if [ -z "$cleandir" ]; then
63 echo "Not removing $file"
66 [ "$quiet" ] ||
echo "Removing $file"
67 if [ "$cleandirhard" ]; then
71 if [ -e "$file" -o -L "$file" ]; then
72 echo "Cannot remove $file"
74 elif [ -e "$file" -o -L "$file" ]; then
75 [ "$quiet" ] ||
echo "Removing $file"
77 # rm would complain itself on failure
79 echo "File $file has disappeared!"