]>
Commit | Line | Data |
---|---|---|
c3b831bd PR |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005-2006 Pavel Roskin | |
4 | # | |
5 | ||
27c0d1c7 PH |
6 | OPTIONS_KEEPDASHDASH= |
7 | OPTIONS_SPEC="\ | |
8 | git-clean [options] <paths>... | |
9 | ||
10 | Clean untracked files from the working directory | |
11 | ||
393e3b19 | 12 | When optional <paths>... arguments are given, the paths |
27c0d1c7 PH |
13 | affected are further limited to those that match them. |
14 | -- | |
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" | |
21 | ||
c3b831bd PR |
22 | SUBDIRECTORY_OK=Yes |
23 | . git-sh-setup | |
7eff28a9 | 24 | require_work_tree |
c3b831bd PR |
25 | |
26 | ignored= | |
27 | ignoredonly= | |
28 | cleandir= | |
7484529d DS |
29 | rmf="rm -f --" |
30 | rmrf="rm -rf --" | |
c3b831bd PR |
31 | rm_refuse="echo Not removing" |
32 | echo1="echo" | |
33 | ||
f192c5d0 | 34 | disabled=$(git config --bool clean.requireForce) |
562ca192 | 35 | |
822f7c73 | 36 | while test $# != 0 |
c3b831bd PR |
37 | do |
38 | case "$1" in | |
39 | -d) | |
40 | cleandir=1 | |
41 | ;; | |
2122591b | 42 | -f) |
f192c5d0 | 43 | disabled=false |
2122591b | 44 | ;; |
c3b831bd | 45 | -n) |
f192c5d0 | 46 | disabled=false |
c3b831bd PR |
47 | rmf="echo Would remove" |
48 | rmrf="echo Would remove" | |
49 | rm_refuse="echo Would not remove" | |
50 | echo1=":" | |
51 | ;; | |
52 | -q) | |
e6d7b2f6 | 53 | echo1=":" |
c3b831bd PR |
54 | ;; |
55 | -x) | |
56 | ignored=1 | |
57 | ;; | |
58 | -X) | |
59 | ignoredonly=1 | |
60 | ;; | |
393e3b19 JH |
61 | --) |
62 | shift | |
63 | break | |
64 | ;; | |
393e3b19 | 65 | *) |
27c0d1c7 PH |
66 | usage # should not happen |
67 | ;; | |
c3b831bd PR |
68 | esac |
69 | shift | |
70 | done | |
71 | ||
f192c5d0 JS |
72 | # requireForce used to default to false but now it defaults to true. |
73 | # IOW, lack of explicit "clean.requireForce = false" is taken as | |
74 | # "clean.requireForce = true". | |
75 | case "$disabled" in | |
76 | "") | |
77 | die "clean.requireForce not set and -n or -f not given; refusing to clean" | |
78 | ;; | |
79 | "true") | |
80 | die "clean.requireForce set and -n or -f not given; refusing to clean" | |
81 | ;; | |
82 | esac | |
2122591b | 83 | |
27c0d1c7 PH |
84 | if [ "$ignored,$ignoredonly" = "1,1" ]; then |
85 | die "-x and -X cannot be set together" | |
86 | fi | |
c3b831bd PR |
87 | |
88 | if [ -z "$ignored" ]; then | |
89 | excl="--exclude-per-directory=.gitignore" | |
b57321f5 | 90 | excl_info= excludes_file= |
c3b831bd PR |
91 | if [ -f "$GIT_DIR/info/exclude" ]; then |
92 | excl_info="--exclude-from=$GIT_DIR/info/exclude" | |
93 | fi | |
b57321f5 JH |
94 | if cfg_excl=$(git config core.excludesfile) && test -f "$cfg_excl" |
95 | then | |
96 | excludes_file="--exclude-from=$cfg_excl" | |
97 | fi | |
c3b831bd PR |
98 | if [ "$ignoredonly" ]; then |
99 | excl="$excl --ignored" | |
100 | fi | |
101 | fi | |
102 | ||
b57321f5 JH |
103 | git ls-files --others --directory \ |
104 | $excl ${excl_info:+"$excl_info"} ${excludes_file:+"$excludes_file"} \ | |
105 | -- "$@" | | |
c3b831bd PR |
106 | while read -r file; do |
107 | if [ -d "$file" -a ! -L "$file" ]; then | |
108 | if [ -z "$cleandir" ]; then | |
109 | $rm_refuse "$file" | |
110 | continue | |
111 | fi | |
112 | $echo1 "Removing $file" | |
113 | $rmrf "$file" | |
114 | else | |
115 | $echo1 "Removing $file" | |
116 | $rmf "$file" | |
117 | fi | |
118 | done |