]>
Commit | Line | Data |
---|---|---|
8464010f DST |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2008 Johannes E. Schindelin | |
4 | # | |
5 | ||
6 | test_description='prune' | |
7 | . ./test-lib.sh | |
8 | ||
98df233e CB |
9 | day=$((60*60*24)) |
10 | week=$(($day*7)) | |
11 | ||
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 | |
18 | } | |
19 | ||
8464010f DST |
20 | test_expect_success setup ' |
21 | ||
22 | : > file && | |
23 | git add file && | |
24 | test_tick && | |
25 | git commit -m initial && | |
26 | git gc | |
27 | ||
28 | ' | |
29 | ||
30 | test_expect_success 'prune stale packs' ' | |
31 | ||
32 | orig_pack=$(echo .git/objects/pack/*.pack) && | |
33 | : > .git/objects/tmp_1.pack && | |
34 | : > .git/objects/tmp_2.pack && | |
21926fe8 | 35 | test-chmtime =-86501 .git/objects/tmp_1.pack && |
8464010f DST |
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 | |
40 | ||
41 | ' | |
42 | ||
25ee9731 JS |
43 | test_expect_success 'prune --expire' ' |
44 | ||
98df233e | 45 | add_blob && |
25ee9731 JS |
46 | git prune --expire=1.hour.ago && |
47 | test $((1 + $before)) = $(git count-objects | sed "s/ .*//") && | |
48 | test -f $BLOB_FILE && | |
21926fe8 | 49 | test-chmtime =-86500 $BLOB_FILE && |
25ee9731 JS |
50 | git prune --expire 1.day && |
51 | test $before = $(git count-objects | sed "s/ .*//") && | |
52 | ! test -f $BLOB_FILE | |
53 | ||
54 | ' | |
55 | ||
56 | test_expect_success 'gc: implicit prune --expire' ' | |
57 | ||
98df233e CB |
58 | add_blob && |
59 | test-chmtime =-$((2*$week-30)) $BLOB_FILE && | |
25ee9731 JS |
60 | git gc && |
61 | test $((1 + $before)) = $(git count-objects | sed "s/ .*//") && | |
62 | test -f $BLOB_FILE && | |
98df233e | 63 | test-chmtime =-$((2*$week+1)) $BLOB_FILE && |
25ee9731 JS |
64 | git gc && |
65 | test $before = $(git count-objects | sed "s/ .*//") && | |
66 | ! test -f $BLOB_FILE | |
67 | ||
68 | ' | |
69 | ||
70 | test_expect_success 'gc: refuse to start with invalid gc.pruneExpire' ' | |
71 | ||
72 | git config gc.pruneExpire invalid && | |
73 | test_must_fail git gc | |
74 | ||
75 | ' | |
76 | ||
77 | test_expect_success 'gc: start with ok gc.pruneExpire' ' | |
78 | ||
79 | git config gc.pruneExpire 2.days.ago && | |
80 | git gc | |
81 | ||
82 | ' | |
83 | ||
0c62705a MB |
84 | test_expect_success 'prune: prune nonsense parameters' ' |
85 | ||
86 | test_must_fail git prune garbage && | |
87 | test_must_fail git prune --- && | |
88 | test_must_fail git prune --no-such-option | |
89 | ||
90 | ' | |
91 | ||
92 | test_expect_success 'prune: prune unreachable heads' ' | |
93 | ||
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 -- | |
103 | ||
104 | ' | |
105 | ||
fe308f53 | 106 | test_expect_success 'prune: do not prune heads listed as an argument' ' |
0c62705a MB |
107 | |
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 -- | |
115 | ||
116 | ' | |
117 | ||
58e9d9d4 JS |
118 | test_expect_success 'gc --no-prune' ' |
119 | ||
98df233e CB |
120 | add_blob && |
121 | test-chmtime =-$((5001*$day)) $BLOB_FILE && | |
58e9d9d4 JS |
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 | |
126 | ||
127 | ' | |
128 | ||
129 | test_expect_success 'gc respects gc.pruneExpire' ' | |
130 | ||
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 | |
137 | ||
138 | ' | |
139 | ||
140 | test_expect_success 'gc --prune=<date>' ' | |
141 | ||
98df233e CB |
142 | add_blob && |
143 | test-chmtime =-$((5001*$day)) $BLOB_FILE && | |
58e9d9d4 JS |
144 | git gc --prune=5002.days.ago && |
145 | test -f $BLOB_FILE && | |
146 | git gc --prune=5000.days.ago && | |
147 | test ! -f $BLOB_FILE | |
148 | ||
149 | ' | |
150 | ||
cbf731ed AS |
151 | test_expect_success 'gc --prune=never' ' |
152 | ||
153 | add_blob && | |
154 | git gc --prune=never && | |
155 | test -f $BLOB_FILE && | |
156 | git gc --prune=now && | |
157 | test ! -f $BLOB_FILE | |
158 | ||
159 | ' | |
160 | ||
161 | test_expect_success 'gc respects gc.pruneExpire=never' ' | |
162 | ||
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 | |
170 | ||
171 | ' | |
172 | ||
173 | test_expect_success 'prune --expire=never' ' | |
174 | ||
175 | add_blob && | |
176 | git prune --expire=never && | |
177 | test -f $BLOB_FILE && | |
178 | git prune && | |
179 | test ! -f $BLOB_FILE | |
180 | ||
181 | ' | |
182 | ||
98df233e CB |
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 && | |
187 | ( | |
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 | |
194 | ) | |
195 | ' | |
196 | ||
8464010f | 197 | test_done |