3 # Copyright (c) 2008 Johannes E. Schindelin
6 test_description='prune'
9 test_expect_success setup '
14 git commit -m initial &&
19 test_expect_success 'prune stale packs' '
21 orig_pack=$(echo .git/objects/pack/*.pack) &&
22 : > .git/objects/tmp_1.pack &&
23 : > .git/objects/tmp_2.pack &&
24 test-chmtime -86501 .git/objects/tmp_1.pack &&
25 git prune --expire 1.day &&
27 test -f .git/objects/tmp_2.pack &&
28 ! test -f .git/objects/tmp_1.pack
32 test_expect_success 'prune --expire' '
34 before=$(git count-objects | sed "s/ .*//") &&
35 BLOB=$(echo aleph | git hash-object -w --stdin) &&
36 BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") &&
37 test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
39 git prune --expire=1.hour.ago &&
40 test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
42 test-chmtime -86500 $BLOB_FILE &&
43 git prune --expire 1.day &&
44 test $before = $(git count-objects | sed "s/ .*//") &&
49 test_expect_success 'gc: implicit prune --expire' '
51 before=$(git count-objects | sed "s/ .*//") &&
52 BLOB=$(echo aleph_0 | git hash-object -w --stdin) &&
53 BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") &&
54 test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
56 test-chmtime -$((86400*14-30)) $BLOB_FILE &&
58 test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
60 test-chmtime -$((86400*14+1)) $BLOB_FILE &&
62 test $before = $(git count-objects | sed "s/ .*//") &&
67 test_expect_success 'gc: refuse to start with invalid gc.pruneExpire' '
69 git config gc.pruneExpire invalid &&
74 test_expect_success 'gc: start with ok gc.pruneExpire' '
76 git config gc.pruneExpire 2.days.ago &&
81 test_expect_success 'prune: prune nonsense parameters' '
83 test_must_fail git prune garbage &&
84 test_must_fail git prune --- &&
85 test_must_fail git prune --no-such-option
89 test_expect_success 'prune: prune unreachable heads' '
91 git config core.logAllRefUpdates false &&
92 mv .git/logs .git/logs.old &&
95 git commit -m temporary &&
96 tmp_head=$(git rev-list -1 HEAD) &&
99 test_must_fail git reset $tmp_head --
103 test_expect_success 'prune: do not prune heads listed as an argument' '
107 git commit -m temporary &&
108 tmp_head=$(git rev-list -1 HEAD) &&
110 git prune -- $tmp_head &&
111 git reset $tmp_head --