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