You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
2.2 KiB
119 lines
2.2 KiB
19 years ago
|
#!/bin/sh
|
||
|
#
|
||
|
# Copyright (c) 2005-2006 Pavel Roskin
|
||
|
#
|
||
|
|
||
17 years ago
|
OPTIONS_KEEPDASHDASH=
|
||
|
OPTIONS_SPEC="\
|
||
|
git-clean [options] <paths>...
|
||
|
|
||
|
Clean untracked files from the working directory
|
||
|
|
||
19 years ago
|
When optional <paths>... arguments are given, the paths
|
||
17 years ago
|
affected are further limited to those that match them.
|
||
|
--
|
||
|
d remove directories as well
|
||
|
f override clean.requireForce and clean anyway
|
||
|
n don't remove anything, just show what would be done
|
||
|
q be quiet, only report errors
|
||
|
x remove ignored files as well
|
||
|
X remove only ignored files"
|
||
|
|
||
19 years ago
|
SUBDIRECTORY_OK=Yes
|
||
|
. git-sh-setup
|
||
18 years ago
|
require_work_tree
|
||
19 years ago
|
|
||
|
ignored=
|
||
|
ignoredonly=
|
||
|
cleandir=
|
||
19 years ago
|
rmf="rm -f --"
|
||
|
rmrf="rm -rf --"
|
||
19 years ago
|
rm_refuse="echo Not removing"
|
||
|
echo1="echo"
|
||
|
|
||
17 years ago
|
disabled=$(git config --bool clean.requireForce)
|
||
17 years ago
|
|
||
18 years ago
|
while test $# != 0
|
||
19 years ago
|
do
|
||
|
case "$1" in
|
||
|
-d)
|
||
|
cleandir=1
|
||
|
;;
|
||
18 years ago
|
-f)
|
||
17 years ago
|
disabled=false
|
||
18 years ago
|
;;
|
||
19 years ago
|
-n)
|
||
17 years ago
|
disabled=false
|
||
19 years ago
|
rmf="echo Would remove"
|
||
|
rmrf="echo Would remove"
|
||
|
rm_refuse="echo Would not remove"
|
||
|
echo1=":"
|
||
|
;;
|
||
|
-q)
|
||
18 years ago
|
echo1=":"
|
||
19 years ago
|
;;
|
||
|
-x)
|
||
|
ignored=1
|
||
|
;;
|
||
|
-X)
|
||
|
ignoredonly=1
|
||
|
;;
|
||
19 years ago
|
--)
|
||
|
shift
|
||
|
break
|
||
|
;;
|
||
|
*)
|
||
17 years ago
|
usage # should not happen
|
||
|
;;
|
||
19 years ago
|
esac
|
||
|
shift
|
||
|
done
|
||
|
|
||
17 years ago
|
# requireForce used to default to false but now it defaults to true.
|
||
|
# IOW, lack of explicit "clean.requireForce = false" is taken as
|
||
|
# "clean.requireForce = true".
|
||
|
case "$disabled" in
|
||
|
"")
|
||
|
die "clean.requireForce not set and -n or -f not given; refusing to clean"
|
||
|
;;
|
||
|
"true")
|
||
|
die "clean.requireForce set and -n or -f not given; refusing to clean"
|
||
|
;;
|
||
|
esac
|
||
18 years ago
|
|
||
17 years ago
|
if [ "$ignored,$ignoredonly" = "1,1" ]; then
|
||
|
die "-x and -X cannot be set together"
|
||
|
fi
|
||
19 years ago
|
|
||
|
if [ -z "$ignored" ]; then
|
||
|
excl="--exclude-per-directory=.gitignore"
|
||
17 years ago
|
excl_info= excludes_file=
|
||
19 years ago
|
if [ -f "$GIT_DIR/info/exclude" ]; then
|
||
|
excl_info="--exclude-from=$GIT_DIR/info/exclude"
|
||
|
fi
|
||
17 years ago
|
if cfg_excl=$(git config core.excludesfile) && test -f "$cfg_excl"
|
||
|
then
|
||
|
excludes_file="--exclude-from=$cfg_excl"
|
||
|
fi
|
||
19 years ago
|
if [ "$ignoredonly" ]; then
|
||
|
excl="$excl --ignored"
|
||
|
fi
|
||
|
fi
|
||
|
|
||
17 years ago
|
git ls-files --others --directory \
|
||
|
$excl ${excl_info:+"$excl_info"} ${excludes_file:+"$excludes_file"} \
|
||
|
-- "$@" |
|
||
19 years ago
|
while read -r file; do
|
||
|
if [ -d "$file" -a ! -L "$file" ]; then
|
||
|
if [ -z "$cleandir" ]; then
|
||
|
$rm_refuse "$file"
|
||
|
continue
|
||
|
fi
|
||
|
$echo1 "Removing $file"
|
||
|
$rmrf "$file"
|
||
|
else
|
||
|
$echo1 "Removing $file"
|
||
|
$rmf "$file"
|
||
|
fi
|
||
|
done
|