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