]>
Commit | Line | Data |
---|---|---|
1389d9dd JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Junio C Hamano | |
4 | # | |
5 | ||
6 | test_description='Test prune and reflog expiration' | |
7 | . ./test-lib.sh | |
8 | ||
9 | check_have () { | |
10 | gaah= && | |
11 | for N in "$@" | |
12 | do | |
13 | eval "o=\$$N" && git cat-file -t $o || { | |
14 | echo Gaah $N | |
15 | gaah=$N | |
16 | break | |
17 | } | |
18 | done && | |
19 | test -z "$gaah" | |
20 | } | |
21 | ||
22 | check_fsck () { | |
df391b19 | 23 | output=$(git fsck --full) |
1389d9dd JH |
24 | case "$1" in |
25 | '') | |
26 | test -z "$output" ;; | |
27 | *) | |
28 | echo "$output" | grep "$1" ;; | |
29 | esac | |
30 | } | |
31 | ||
32 | corrupt () { | |
33 | aa=${1%??????????????????????????????????????} zz=${1#??} | |
34 | mv .git/objects/$aa/$zz .git/$aa$zz | |
35 | } | |
36 | ||
37 | recover () { | |
38 | aa=${1%??????????????????????????????????????} zz=${1#??} | |
39 | mkdir -p .git/objects/$aa | |
40 | mv .git/$aa$zz .git/objects/$aa/$zz | |
41 | } | |
42 | ||
43 | check_dont_have () { | |
44 | gaah= && | |
45 | for N in "$@" | |
46 | do | |
47 | eval "o=\$$N" | |
48 | git cat-file -t $o && { | |
49 | echo Gaah $N | |
50 | gaah=$N | |
51 | break | |
52 | } | |
53 | done | |
54 | test -z "$gaah" | |
55 | } | |
56 | ||
57 | test_expect_success setup ' | |
58 | mkdir -p A/B && | |
59 | echo rat >C && | |
60 | echo ox >A/D && | |
61 | echo tiger >A/B/E && | |
62 | git add . && | |
63 | ||
64 | test_tick && git commit -m rabbit && | |
65 | H=`git rev-parse --verify HEAD` && | |
66 | A=`git rev-parse --verify HEAD:A` && | |
67 | B=`git rev-parse --verify HEAD:A/B` && | |
68 | C=`git rev-parse --verify HEAD:C` && | |
69 | D=`git rev-parse --verify HEAD:A/D` && | |
70 | E=`git rev-parse --verify HEAD:A/B/E` && | |
71 | check_fsck && | |
72 | ||
1f553918 | 73 | test_chmod +x C && |
1389d9dd JH |
74 | git add C && |
75 | test_tick && git commit -m dragon && | |
76 | L=`git rev-parse --verify HEAD` && | |
77 | check_fsck && | |
78 | ||
79 | rm -f C A/B/E && | |
80 | echo snake >F && | |
81 | echo horse >A/G && | |
82 | git add F A/G && | |
83 | test_tick && git commit -a -m sheep && | |
84 | F=`git rev-parse --verify HEAD:F` && | |
85 | G=`git rev-parse --verify HEAD:A/G` && | |
86 | I=`git rev-parse --verify HEAD:A` && | |
87 | J=`git rev-parse --verify HEAD` && | |
88 | check_fsck && | |
89 | ||
90 | rm -f A/G && | |
91 | test_tick && git commit -a -m monkey && | |
92 | K=`git rev-parse --verify HEAD` && | |
93 | check_fsck && | |
94 | ||
95 | check_have A B C D E F G H I J K L && | |
96 | ||
026aa938 | 97 | git prune && |
1389d9dd JH |
98 | |
99 | check_have A B C D E F G H I J K L && | |
100 | ||
101 | check_fsck && | |
102 | ||
103 | loglen=$(wc -l <.git/logs/refs/heads/master) && | |
104 | test $loglen = 4 | |
105 | ' | |
106 | ||
107 | test_expect_success rewind ' | |
108 | test_tick && git reset --hard HEAD~2 && | |
109 | test -f C && | |
110 | test -f A/B/E && | |
111 | ! test -f F && | |
112 | ! test -f A/G && | |
113 | ||
114 | check_have A B C D E F G H I J K L && | |
115 | ||
026aa938 | 116 | git prune && |
1389d9dd JH |
117 | |
118 | check_have A B C D E F G H I J K L && | |
119 | ||
120 | loglen=$(wc -l <.git/logs/refs/heads/master) && | |
121 | test $loglen = 5 | |
122 | ' | |
123 | ||
124 | test_expect_success 'corrupt and check' ' | |
125 | ||
126 | corrupt $F && | |
127 | check_fsck "missing blob $F" | |
128 | ||
129 | ' | |
130 | ||
131 | test_expect_success 'reflog expire --dry-run should not touch reflog' ' | |
132 | ||
133 | git reflog expire --dry-run \ | |
134 | --expire=$(($test_tick - 10000)) \ | |
135 | --expire-unreachable=$(($test_tick - 10000)) \ | |
136 | --stale-fix \ | |
137 | --all && | |
138 | ||
139 | loglen=$(wc -l <.git/logs/refs/heads/master) && | |
140 | test $loglen = 5 && | |
141 | ||
142 | check_fsck "missing blob $F" | |
143 | ' | |
144 | ||
145 | test_expect_success 'reflog expire' ' | |
146 | ||
147 | git reflog expire --verbose \ | |
148 | --expire=$(($test_tick - 10000)) \ | |
149 | --expire-unreachable=$(($test_tick - 10000)) \ | |
150 | --stale-fix \ | |
151 | --all && | |
152 | ||
153 | loglen=$(wc -l <.git/logs/refs/heads/master) && | |
154 | test $loglen = 2 && | |
155 | ||
156 | check_fsck "dangling commit $K" | |
157 | ' | |
158 | ||
159 | test_expect_success 'prune and fsck' ' | |
160 | ||
026aa938 | 161 | git prune && |
1389d9dd JH |
162 | check_fsck && |
163 | ||
164 | check_have A B C D E H L && | |
165 | check_dont_have F G I J K | |
166 | ||
167 | ' | |
168 | ||
169 | test_expect_success 'recover and check' ' | |
170 | ||
171 | recover $F && | |
172 | check_fsck "dangling blob $F" | |
173 | ||
174 | ' | |
175 | ||
55beff4f | 176 | test_expect_success 'delete' ' |
552cecc2 JS |
177 | echo 1 > C && |
178 | test_tick && | |
179 | git commit -m rat C && | |
180 | ||
181 | echo 2 > C && | |
182 | test_tick && | |
183 | git commit -m ox C && | |
184 | ||
185 | echo 3 > C && | |
186 | test_tick && | |
187 | git commit -m tiger C && | |
188 | ||
a48fcd83 JN |
189 | HEAD_entry_count=$(git reflog | wc -l) && |
190 | master_entry_count=$(git reflog show master | wc -l) && | |
38881a90 PB |
191 | |
192 | test $HEAD_entry_count = 5 && | |
193 | test $master_entry_count = 5 && | |
194 | ||
552cecc2 JS |
195 | |
196 | git reflog delete master@{1} && | |
197 | git reflog show master > output && | |
38881a90 PB |
198 | test $(($master_entry_count - 1)) = $(wc -l < output) && |
199 | test $HEAD_entry_count = $(git reflog | wc -l) && | |
552cecc2 JS |
200 | ! grep ox < output && |
201 | ||
a48fcd83 | 202 | master_entry_count=$(wc -l < output) && |
38881a90 PB |
203 | |
204 | git reflog delete HEAD@{1} && | |
205 | test $(($HEAD_entry_count -1)) = $(git reflog | wc -l) && | |
206 | test $master_entry_count = $(git reflog show master | wc -l) && | |
207 | ||
a48fcd83 | 208 | HEAD_entry_count=$(git reflog | wc -l) && |
38881a90 | 209 | |
552cecc2 JS |
210 | git reflog delete master@{07.04.2005.15:15:00.-0700} && |
211 | git reflog show master > output && | |
38881a90 | 212 | test $(($master_entry_count - 1)) = $(wc -l < output) && |
552cecc2 | 213 | ! grep dragon < output |
50f3ac29 JH |
214 | |
215 | ' | |
216 | ||
4a9f4394 AS |
217 | test_expect_success 'rewind2' ' |
218 | ||
219 | test_tick && git reset --hard HEAD~2 && | |
220 | loglen=$(wc -l <.git/logs/refs/heads/master) && | |
221 | test $loglen = 4 | |
222 | ||
223 | ' | |
224 | ||
225 | test_expect_success '--expire=never' ' | |
226 | ||
227 | git reflog expire --verbose \ | |
228 | --expire=never \ | |
229 | --expire-unreachable=never \ | |
230 | --all && | |
231 | loglen=$(wc -l <.git/logs/refs/heads/master) && | |
232 | test $loglen = 4 | |
233 | ||
234 | ' | |
235 | ||
236 | test_expect_success 'gc.reflogexpire=never' ' | |
237 | ||
238 | git config gc.reflogexpire never && | |
239 | git config gc.reflogexpireunreachable never && | |
240 | git reflog expire --verbose --all && | |
241 | loglen=$(wc -l <.git/logs/refs/heads/master) && | |
242 | test $loglen = 4 | |
243 | ' | |
244 | ||
245 | test_expect_success 'gc.reflogexpire=false' ' | |
246 | ||
247 | git config gc.reflogexpire false && | |
248 | git config gc.reflogexpireunreachable false && | |
249 | git reflog expire --verbose --all && | |
250 | loglen=$(wc -l <.git/logs/refs/heads/master) && | |
251 | test $loglen = 4 && | |
252 | ||
253 | git config --unset gc.reflogexpire && | |
254 | git config --unset gc.reflogexpireunreachable | |
255 | ||
256 | ' | |
257 | ||
1389d9dd | 258 | test_done |