Skip to content

Commit

Permalink
clean: require -f to do damage by default
Browse files Browse the repository at this point in the history
This makes the clean.requireForce configuration default to true.
Too many people are burned by typing "git clean" by mistake when
they meant to say "make clean".

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Nov 4, 2007
1 parent ee78740 commit 562ca19
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ branch.<name>.merge::
`.` (a period) for branch.<name>.remote.

clean.requireForce::
A boolean to make git-clean do nothing unless given -f or -n. Defaults
to false.
A boolean to make git-clean do nothing unless given -f
or -n. Defaults to true.

color.branch::
A boolean to enable/disable color in the output of
Expand Down
6 changes: 5 additions & 1 deletion git-clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ require_work_tree
ignored=
ignoredonly=
cleandir=
disabled="`git config --bool clean.requireForce`"
rmf="rm -f --"
rmrf="rm -rf --"
rm_refuse="echo Not removing"
echo1="echo"

# 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".
disabled=$(git config --bool clean.requireForce || echo true)

while test $# != 0
do
case "$1" in
Expand Down
12 changes: 6 additions & 6 deletions t/t7201-co.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ test_expect_success "checkout with dirty tree without -m" '
test_expect_success "checkout -m with dirty tree" '
git checkout -f master &&
git clean &&
git clean -f &&
fill 0 1 2 3 4 5 6 7 8 >one &&
git checkout -m side &&
Expand All @@ -99,7 +99,7 @@ test_expect_success "checkout -m with dirty tree" '

test_expect_success "checkout -m with dirty tree, renamed" '
git checkout -f master && git clean &&
git checkout -f master && git clean -f &&
fill 1 2 3 4 5 7 8 >one &&
if git checkout renamer
Expand All @@ -121,7 +121,7 @@ test_expect_success "checkout -m with dirty tree, renamed" '

test_expect_success 'checkout -m with merge conflict' '
git checkout -f master && git clean &&
git checkout -f master && git clean -f &&
fill 1 T 3 4 5 6 S 8 >one &&
if git checkout renamer
Expand All @@ -144,7 +144,7 @@ test_expect_success 'checkout -m with merge conflict' '

test_expect_success 'checkout to detach HEAD' '
git checkout -f renamer && git clean &&
git checkout -f renamer && git clean -f &&
git checkout renamer^ &&
H=$(git rev-parse --verify HEAD) &&
M=$(git show-ref -s --verify refs/heads/master) &&
Expand All @@ -160,7 +160,7 @@ test_expect_success 'checkout to detach HEAD' '

test_expect_success 'checkout to detach HEAD with branchname^' '
git checkout -f master && git clean &&
git checkout -f master && git clean -f &&
git checkout renamer^ &&
H=$(git rev-parse --verify HEAD) &&
M=$(git show-ref -s --verify refs/heads/master) &&
Expand All @@ -176,7 +176,7 @@ test_expect_success 'checkout to detach HEAD with branchname^' '

test_expect_success 'checkout to detach HEAD with HEAD^0' '
git checkout -f master && git clean &&
git checkout -f master && git clean -f &&
git checkout HEAD^0 &&
H=$(git rev-parse --verify HEAD) &&
M=$(git show-ref -s --verify refs/heads/master) &&
Expand Down
9 changes: 9 additions & 0 deletions t/t7300-clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ test_description='git-clean basic tests'

. ./test-lib.sh

git config clean.requireForce no

test_expect_success 'setup' '
mkdir -p src &&
Expand Down Expand Up @@ -139,6 +141,13 @@ test_expect_success 'git-clean -d -X' '
'

test_expect_success 'clean.requireForce defaults to true' '
git config --unset clean.requireForce &&
! git-clean
'

test_expect_success 'clean.requireForce' '
git config clean.requireForce true &&
Expand Down

0 comments on commit 562ca19

Please sign in to comment.