Pavel Roskin | c3b831b | 2006-04-05 02:00:48 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2005-2006 Pavel Roskin |
| 4 | # |
| 5 | |
Junio C Hamano | 393e3b1 | 2006-05-08 12:02:44 -0700 | [diff] [blame] | 6 | USAGE="[-d] [-n] [-q] [-x | -X] [--] <paths>..." |
Pavel Roskin | c3b831b | 2006-04-05 02:00:48 -0400 | [diff] [blame] | 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 |
Junio C Hamano | 393e3b1 | 2006-05-08 12:02:44 -0700 | [diff] [blame] | 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.' |
Pavel Roskin | c3b831b | 2006-04-05 02:00:48 -0400 | [diff] [blame] | 15 | SUBDIRECTORY_OK=Yes |
| 16 | . git-sh-setup |
| 17 | |
| 18 | ignored= |
| 19 | ignoredonly= |
| 20 | cleandir= |
| 21 | quiet= |
Dennis Stosberg | 7484529 | 2006-05-29 17:06:32 +0200 | [diff] [blame] | 22 | rmf="rm -f --" |
| 23 | rmrf="rm -rf --" |
Pavel Roskin | c3b831b | 2006-04-05 02:00:48 -0400 | [diff] [blame] | 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) |
| 34 | quiet=1 |
| 35 | rmf="echo Would remove" |
| 36 | rmrf="echo Would remove" |
| 37 | rm_refuse="echo Would not remove" |
| 38 | echo1=":" |
| 39 | ;; |
| 40 | -q) |
| 41 | quiet=1 |
| 42 | ;; |
| 43 | -x) |
| 44 | ignored=1 |
| 45 | ;; |
| 46 | -X) |
| 47 | ignoredonly=1 |
| 48 | ;; |
Junio C Hamano | 393e3b1 | 2006-05-08 12:02:44 -0700 | [diff] [blame] | 49 | --) |
| 50 | shift |
| 51 | break |
| 52 | ;; |
| 53 | -*) |
Pavel Roskin | c3b831b | 2006-04-05 02:00:48 -0400 | [diff] [blame] | 54 | usage |
Junio C Hamano | 393e3b1 | 2006-05-08 12:02:44 -0700 | [diff] [blame] | 55 | ;; |
| 56 | *) |
| 57 | break |
Pavel Roskin | c3b831b | 2006-04-05 02:00:48 -0400 | [diff] [blame] | 58 | esac |
| 59 | shift |
| 60 | done |
| 61 | |
| 62 | case "$ignored,$ignoredonly" in |
| 63 | 1,1) usage;; |
| 64 | esac |
| 65 | |
| 66 | if [ -z "$ignored" ]; then |
| 67 | excl="--exclude-per-directory=.gitignore" |
| 68 | if [ -f "$GIT_DIR/info/exclude" ]; then |
| 69 | excl_info="--exclude-from=$GIT_DIR/info/exclude" |
| 70 | fi |
| 71 | if [ "$ignoredonly" ]; then |
| 72 | excl="$excl --ignored" |
| 73 | fi |
| 74 | fi |
| 75 | |
Junio C Hamano | 393e3b1 | 2006-05-08 12:02:44 -0700 | [diff] [blame] | 76 | git-ls-files --others --directory $excl ${excl_info:+"$excl_info"} -- "$@" | |
Pavel Roskin | c3b831b | 2006-04-05 02:00:48 -0400 | [diff] [blame] | 77 | while read -r file; do |
| 78 | if [ -d "$file" -a ! -L "$file" ]; then |
| 79 | if [ -z "$cleandir" ]; then |
| 80 | $rm_refuse "$file" |
| 81 | continue |
| 82 | fi |
| 83 | $echo1 "Removing $file" |
| 84 | $rmrf "$file" |
| 85 | else |
| 86 | $echo1 "Removing $file" |
| 87 | $rmf "$file" |
| 88 | fi |
| 89 | done |