#!/bin/sh # # Copyright (c) 2005-2006 Pavel Roskin # setglobal OPTIONS_KEEPDASHDASH = '' setglobal OPTIONS_SPEC = '"\ git-clean [options] ... Clean untracked files from the working directory When optional ... arguments are given, the paths affected are further limited to those that match them. -- d remove directories as well f override clean.requireForce and clean anyway n don't remove anything, just show what would be done q be quiet, only report errors x remove ignored files as well X remove only ignored files'" setglobal SUBDIRECTORY_OK = 'Yes' source git-sh-setup require_work_tree setglobal ignored = '' setglobal ignoredonly = '' setglobal cleandir = '' setglobal rmf = '"rm -f --'" setglobal rmrf = '"rm -rf --'" setglobal rm_refuse = '"echo Not removing'" setglobal echo1 = '"echo'" setglobal disabled = $[git config --bool clean.requireForce] while test $# != 0 { match $1 { with -d setglobal cleandir = '1' with -f setglobal disabled = 'false' with -n setglobal disabled = 'false' setglobal rmf = '"echo Would remove'" setglobal rmrf = '"echo Would remove'" setglobal rm_refuse = '"echo Would not remove'" setglobal echo1 = '":'" with -q setglobal echo1 = '":'" with -x setglobal ignored = '1' with -X setglobal ignoredonly = '1' with -- shift break with * usage # should not happen } shift } # requireForce used to default to false but now it defaults to true. # IOW, lack of explicit "clean.requireForce = false" is taken as # "clean.requireForce = true". match $disabled { with "" die "clean.requireForce not set and -n or -f not given; refusing to clean" with "true" die "clean.requireForce set and -n or -f not given; refusing to clean" } if test "$ignored,$ignoredonly" = "1,1" { die "-x and -X cannot be set together" } if test -z $ignored { setglobal excl = '"--exclude-per-directory=.gitignore'" setglobal excl_info = '', excludes_file = '' if test -f "$GIT_DIR/info/exclude" { setglobal excl_info = ""--exclude-from=$GIT_DIR/info/exclude"" } if setglobal cfg_excl = $[git config core.excludesfile] && test -f $cfg_excl { setglobal excludes_file = ""--exclude-from=$cfg_excl"" } if test $ignoredonly { setglobal excl = ""$excl --ignored"" } } git ls-files --others --directory \ $excl $(excl_info:+"$excl_info") $(excludes_file:+"$excludes_file") \ -- @Argv | while read -r file { if test -d $file -a ! -L $file { if test -z $cleandir { $rm_refuse $file continue } $echo1 "Removing $file" $rmrf $file } else { $echo1 "Removing $file" $rmf $file } }