send-pack: check ref->status before updating tracking refs
[git/jnareb-git.git] / git-clean.sh
blob521fabc20f9a7bbee222cb60c937e8c0f15b8fd6
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 disabled=$(git config --bool clean.requireForce)
30 while test $# != 0
32 case "$1" in
33 -d)
34 cleandir=1
36 -f)
37 disabled=false
39 -n)
40 disabled=false
41 rmf="echo Would remove"
42 rmrf="echo Would remove"
43 rm_refuse="echo Would not remove"
44 echo1=":"
46 -q)
47 echo1=":"
49 -x)
50 ignored=1
52 -X)
53 ignoredonly=1
55 --)
56 shift
57 break
59 -*)
60 usage
63 break
64 esac
65 shift
66 done
68 # requireForce used to default to false but now it defaults to true.
69 # IOW, lack of explicit "clean.requireForce = false" is taken as
70 # "clean.requireForce = true".
71 case "$disabled" in
72 "")
73 die "clean.requireForce not set and -n or -f not given; refusing to clean"
75 "true")
76 die "clean.requireForce set and -n or -f not given; refusing to clean"
78 esac
80 case "$ignored,$ignoredonly" in
81 1,1) usage;;
82 esac
84 if [ -z "$ignored" ]; then
85 excl="--exclude-per-directory=.gitignore"
86 if [ -f "$GIT_DIR/info/exclude" ]; then
87 excl_info="--exclude-from=$GIT_DIR/info/exclude"
89 if [ "$ignoredonly" ]; then
90 excl="$excl --ignored"
94 git ls-files --others --directory $excl ${excl_info:+"$excl_info"} -- "$@" |
95 while read -r file; do
96 if [ -d "$file" -a ! -L "$file" ]; then
97 if [ -z "$cleandir" ]; then
98 $rm_refuse "$file"
99 continue
101 $echo1 "Removing $file"
102 $rmrf "$file"
103 else
104 $echo1 "Removing $file"
105 $rmf "$file"
107 done