Merge branch 'ks/recursive-rename-add-identical'
[git/debian.git] / t / t5304-prune.sh
blobe2ed13dba2705b15d6a1f623589acce134749fab
1 #!/bin/sh
3 # Copyright (c) 2008 Johannes E. Schindelin
6 test_description='prune'
7 . ./test-lib.sh
9 day=$((60*60*24))
10 week=$(($day*7))
12 add_blob() {
13 before=$(git count-objects | sed "s/ .*//") &&
14 BLOB=$(echo aleph_0 | git hash-object -w --stdin) &&
15 BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") &&
16 test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
17 test -f $BLOB_FILE
20 test_expect_success setup '
22 : > file &&
23 git add file &&
24 test_tick &&
25 git commit -m initial &&
26 git gc
30 test_expect_success 'prune stale packs' '
32 orig_pack=$(echo .git/objects/pack/*.pack) &&
33 : > .git/objects/tmp_1.pack &&
34 : > .git/objects/tmp_2.pack &&
35 test-chmtime =-86501 .git/objects/tmp_1.pack &&
36 git prune --expire 1.day &&
37 test -f $orig_pack &&
38 test -f .git/objects/tmp_2.pack &&
39 ! test -f .git/objects/tmp_1.pack
43 test_expect_success 'prune --expire' '
45 add_blob &&
46 git prune --expire=1.hour.ago &&
47 test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
48 test -f $BLOB_FILE &&
49 test-chmtime =-86500 $BLOB_FILE &&
50 git prune --expire 1.day &&
51 test $before = $(git count-objects | sed "s/ .*//") &&
52 ! test -f $BLOB_FILE
56 test_expect_success 'gc: implicit prune --expire' '
58 add_blob &&
59 test-chmtime =-$((2*$week-30)) $BLOB_FILE &&
60 git gc &&
61 test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
62 test -f $BLOB_FILE &&
63 test-chmtime =-$((2*$week+1)) $BLOB_FILE &&
64 git gc &&
65 test $before = $(git count-objects | sed "s/ .*//") &&
66 ! test -f $BLOB_FILE
70 test_expect_success 'gc: refuse to start with invalid gc.pruneExpire' '
72 git config gc.pruneExpire invalid &&
73 test_must_fail git gc
77 test_expect_success 'gc: start with ok gc.pruneExpire' '
79 git config gc.pruneExpire 2.days.ago &&
80 git gc
84 test_expect_success 'prune: prune nonsense parameters' '
86 test_must_fail git prune garbage &&
87 test_must_fail git prune --- &&
88 test_must_fail git prune --no-such-option
92 test_expect_success 'prune: prune unreachable heads' '
94 git config core.logAllRefUpdates false &&
95 mv .git/logs .git/logs.old &&
96 : > file2 &&
97 git add file2 &&
98 git commit -m temporary &&
99 tmp_head=$(git rev-list -1 HEAD) &&
100 git reset HEAD^ &&
101 git prune &&
102 test_must_fail git reset $tmp_head --
106 test_expect_success 'prune: do not prune heads listed as an argument' '
108 : > file2 &&
109 git add file2 &&
110 git commit -m temporary &&
111 tmp_head=$(git rev-list -1 HEAD) &&
112 git reset HEAD^ &&
113 git prune -- $tmp_head &&
114 git reset $tmp_head --
118 test_expect_success 'gc --no-prune' '
120 add_blob &&
121 test-chmtime =-$((5001*$day)) $BLOB_FILE &&
122 git config gc.pruneExpire 2.days.ago &&
123 git gc --no-prune &&
124 test 1 = $(git count-objects | sed "s/ .*//") &&
125 test -f $BLOB_FILE
129 test_expect_success 'gc respects gc.pruneExpire' '
131 git config gc.pruneExpire 5002.days.ago &&
132 git gc &&
133 test -f $BLOB_FILE &&
134 git config gc.pruneExpire 5000.days.ago &&
135 git gc &&
136 test ! -f $BLOB_FILE
140 test_expect_success 'gc --prune=<date>' '
142 add_blob &&
143 test-chmtime =-$((5001*$day)) $BLOB_FILE &&
144 git gc --prune=5002.days.ago &&
145 test -f $BLOB_FILE &&
146 git gc --prune=5000.days.ago &&
147 test ! -f $BLOB_FILE
151 test_expect_success 'gc --prune=never' '
153 add_blob &&
154 git gc --prune=never &&
155 test -f $BLOB_FILE &&
156 git gc --prune=now &&
157 test ! -f $BLOB_FILE
161 test_expect_success 'gc respects gc.pruneExpire=never' '
163 git config gc.pruneExpire never &&
164 add_blob &&
165 git gc &&
166 test -f $BLOB_FILE &&
167 git config gc.pruneExpire now &&
168 git gc &&
169 test ! -f $BLOB_FILE
173 test_expect_success 'prune --expire=never' '
175 add_blob &&
176 git prune --expire=never &&
177 test -f $BLOB_FILE &&
178 git prune &&
179 test ! -f $BLOB_FILE
183 test_expect_success 'gc: prune old objects after local clone' '
184 add_blob &&
185 test-chmtime =-$((2*$week+1)) $BLOB_FILE &&
186 git clone --no-hardlinks . aclone &&
188 cd aclone &&
189 test 1 = $(git count-objects | sed "s/ .*//") &&
190 test -f $BLOB_FILE &&
191 git gc --prune &&
192 test 0 = $(git count-objects | sed "s/ .*//") &&
193 ! test -f $BLOB_FILE
197 test_done