Merge pull request #285 from dscho/readme
[git/mingw/4msysgit.git] / t / t1410-reflog.sh
blob8cab06f90a52b82518aca6f7baa0530eb77ab986
1 #!/bin/sh
3 # Copyright (c) 2007 Junio C Hamano
6 test_description='Test prune and reflog expiration'
7 . ./test-lib.sh
9 check_have () {
10 gaah= &&
11 for N in "$@"
13 eval "o=\$$N" && git cat-file -t $o || {
14 echo Gaah $N
15 gaah=$N
16 break
18 done &&
19 test -z "$gaah"
22 check_fsck () {
23 output=$(git fsck --full)
24 case "$1" in
25 '')
26 test -z "$output" ;;
28 echo "$output" | grep "$1" ;;
29 esac
32 corrupt () {
33 aa=${1%??????????????????????????????????????} zz=${1#??}
34 mv .git/objects/$aa/$zz .git/$aa$zz
37 recover () {
38 aa=${1%??????????????????????????????????????} zz=${1#??}
39 mkdir -p .git/objects/$aa
40 mv .git/$aa$zz .git/objects/$aa/$zz
43 check_dont_have () {
44 gaah= &&
45 for N in "$@"
47 eval "o=\$$N"
48 git cat-file -t $o && {
49 echo Gaah $N
50 gaah=$N
51 break
53 done
54 test -z "$gaah"
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 . &&
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 &&
73 test_chmod +x C &&
74 git add C &&
75 test_tick && git commit -m dragon &&
76 L=`git rev-parse --verify HEAD` &&
77 check_fsck &&
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 &&
90 rm -f A/G &&
91 test_tick && git commit -a -m monkey &&
92 K=`git rev-parse --verify HEAD` &&
93 check_fsck &&
95 check_have A B C D E F G H I J K L &&
97 git prune &&
99 check_have A B C D E F G H I J K L &&
101 check_fsck &&
103 test_line_count = 4 .git/logs/refs/heads/master
106 test_expect_success rewind '
107 test_tick && git reset --hard HEAD~2 &&
108 test -f C &&
109 test -f A/B/E &&
110 ! test -f F &&
111 ! test -f A/G &&
113 check_have A B C D E F G H I J K L &&
115 git prune &&
117 check_have A B C D E F G H I J K L &&
119 test_line_count = 5 .git/logs/refs/heads/master
122 test_expect_success 'corrupt and check' '
124 corrupt $F &&
125 check_fsck "missing blob $F"
129 test_expect_success 'reflog expire --dry-run should not touch reflog' '
131 git reflog expire --dry-run \
132 --expire=$(($test_tick - 10000)) \
133 --expire-unreachable=$(($test_tick - 10000)) \
134 --stale-fix \
135 --all &&
137 test_line_count = 5 .git/logs/refs/heads/master &&
139 check_fsck "missing blob $F"
142 test_expect_success 'reflog expire' '
144 git reflog expire --verbose \
145 --expire=$(($test_tick - 10000)) \
146 --expire-unreachable=$(($test_tick - 10000)) \
147 --stale-fix \
148 --all &&
150 test_line_count = 2 .git/logs/refs/heads/master &&
152 check_fsck "dangling commit $K"
155 test_expect_success 'prune and fsck' '
157 git prune &&
158 check_fsck &&
160 check_have A B C D E H L &&
161 check_dont_have F G I J K
165 test_expect_success 'recover and check' '
167 recover $F &&
168 check_fsck "dangling blob $F"
172 test_expect_success 'delete' '
173 echo 1 > C &&
174 test_tick &&
175 git commit -m rat C &&
177 echo 2 > C &&
178 test_tick &&
179 git commit -m ox C &&
181 echo 3 > C &&
182 test_tick &&
183 git commit -m tiger C &&
185 HEAD_entry_count=$(git reflog | wc -l) &&
186 master_entry_count=$(git reflog show master | wc -l) &&
188 test $HEAD_entry_count = 5 &&
189 test $master_entry_count = 5 &&
192 git reflog delete master@{1} &&
193 git reflog show master > output &&
194 test $(($master_entry_count - 1)) = $(wc -l < output) &&
195 test $HEAD_entry_count = $(git reflog | wc -l) &&
196 ! grep ox < output &&
198 master_entry_count=$(wc -l < output) &&
200 git reflog delete HEAD@{1} &&
201 test $(($HEAD_entry_count -1)) = $(git reflog | wc -l) &&
202 test $master_entry_count = $(git reflog show master | wc -l) &&
204 HEAD_entry_count=$(git reflog | wc -l) &&
206 git reflog delete master@{07.04.2005.15:15:00.-0700} &&
207 git reflog show master > output &&
208 test $(($master_entry_count - 1)) = $(wc -l < output) &&
209 ! grep dragon < output
213 test_expect_success 'rewind2' '
215 test_tick && git reset --hard HEAD~2 &&
216 test_line_count = 4 .git/logs/refs/heads/master
219 test_expect_success '--expire=never' '
221 git reflog expire --verbose \
222 --expire=never \
223 --expire-unreachable=never \
224 --all &&
225 test_line_count = 4 .git/logs/refs/heads/master
228 test_expect_success 'gc.reflogexpire=never' '
230 git config gc.reflogexpire never &&
231 git config gc.reflogexpireunreachable never &&
232 git reflog expire --verbose --all &&
233 test_line_count = 4 .git/logs/refs/heads/master
236 test_expect_success 'gc.reflogexpire=false' '
238 git config gc.reflogexpire false &&
239 git config gc.reflogexpireunreachable false &&
240 git reflog expire --verbose --all &&
241 test_line_count = 4 .git/logs/refs/heads/master &&
243 git config --unset gc.reflogexpire &&
244 git config --unset gc.reflogexpireunreachable
248 test_expect_success 'checkout should not delete log for packed ref' '
249 test $(git reflog master | wc -l) = 4 &&
250 git branch foo &&
251 git pack-refs --all &&
252 git checkout foo &&
253 test $(git reflog master | wc -l) = 4
256 test_done