]>
Commit | Line | Data |
---|---|---|
c3b831bd PR |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005-2006 Pavel Roskin | |
4 | # | |
5 | ||
393e3b19 | 6 | USAGE="[-d] [-n] [-q] [-x | -X] [--] <paths>..." |
c3b831bd PR |
7 | LONG_USAGE='Clean untracked files from the working directory |
8 | -d remove directories as well | |
9 | -n don'\''t remove anything, just show what would be done | |
10 | -q be quiet, only report errors | |
11 | -x remove ignored files as well | |
393e3b19 JH |
12 | -X remove only ignored files |
13 | When optional <paths>... arguments are given, the paths | |
14 | affected are further limited to those that match them.' | |
c3b831bd PR |
15 | SUBDIRECTORY_OK=Yes |
16 | . git-sh-setup | |
7eff28a9 | 17 | require_work_tree |
c3b831bd PR |
18 | |
19 | ignored= | |
20 | ignoredonly= | |
21 | cleandir= | |
7484529d DS |
22 | rmf="rm -f --" |
23 | rmrf="rm -rf --" | |
c3b831bd PR |
24 | rm_refuse="echo Not removing" |
25 | echo1="echo" | |
26 | ||
27 | while case "$#" in 0) break ;; esac | |
28 | do | |
29 | case "$1" in | |
30 | -d) | |
31 | cleandir=1 | |
32 | ;; | |
33 | -n) | |
c3b831bd PR |
34 | rmf="echo Would remove" |
35 | rmrf="echo Would remove" | |
36 | rm_refuse="echo Would not remove" | |
37 | echo1=":" | |
38 | ;; | |
39 | -q) | |
e6d7b2f6 | 40 | echo1=":" |
c3b831bd PR |
41 | ;; |
42 | -x) | |
43 | ignored=1 | |
44 | ;; | |
45 | -X) | |
46 | ignoredonly=1 | |
47 | ;; | |
393e3b19 JH |
48 | --) |
49 | shift | |
50 | break | |
51 | ;; | |
52 | -*) | |
c3b831bd | 53 | usage |
393e3b19 JH |
54 | ;; |
55 | *) | |
56 | break | |
c3b831bd PR |
57 | esac |
58 | shift | |
59 | done | |
60 | ||
61 | case "$ignored,$ignoredonly" in | |
62 | 1,1) usage;; | |
63 | esac | |
64 | ||
65 | if [ -z "$ignored" ]; then | |
66 | excl="--exclude-per-directory=.gitignore" | |
67 | if [ -f "$GIT_DIR/info/exclude" ]; then | |
68 | excl_info="--exclude-from=$GIT_DIR/info/exclude" | |
69 | fi | |
70 | if [ "$ignoredonly" ]; then | |
71 | excl="$excl --ignored" | |
72 | fi | |
73 | fi | |
74 | ||
393e3b19 | 75 | git-ls-files --others --directory $excl ${excl_info:+"$excl_info"} -- "$@" | |
c3b831bd PR |
76 | while read -r file; do |
77 | if [ -d "$file" -a ! -L "$file" ]; then | |
78 | if [ -z "$cleandir" ]; then | |
79 | $rm_refuse "$file" | |
80 | continue | |
81 | fi | |
82 | $echo1 "Removing $file" | |
83 | $rmrf "$file" | |
84 | else | |
85 | $echo1 "Removing $file" | |
86 | $rmf "$file" | |
87 | fi | |
88 | done |