Merge branch 'maint'
[git/jnareb-git.git] / t / t1410-reflog.sh
blobe5bbc384f7f4e56b13a13bf2bedad1427e257652
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 chmod +x C &&
74 ( test "`git config --bool core.filemode`" != false ||
75 echo executable >>C ) &&
76 git add C &&
77 test_tick && git commit -m dragon &&
78 L=`git rev-parse --verify HEAD` &&
79 check_fsck &&
81 rm -f C A/B/E &&
82 echo snake >F &&
83 echo horse >A/G &&
84 git add F A/G &&
85 test_tick && git commit -a -m sheep &&
86 F=`git rev-parse --verify HEAD:F` &&
87 G=`git rev-parse --verify HEAD:A/G` &&
88 I=`git rev-parse --verify HEAD:A` &&
89 J=`git rev-parse --verify HEAD` &&
90 check_fsck &&
92 rm -f A/G &&
93 test_tick && git commit -a -m monkey &&
94 K=`git rev-parse --verify HEAD` &&
95 check_fsck &&
97 check_have A B C D E F G H I J K L &&
99 git prune &&
101 check_have A B C D E F G H I J K L &&
103 check_fsck &&
105 loglen=$(wc -l <.git/logs/refs/heads/master) &&
106 test $loglen = 4
109 test_expect_success rewind '
110 test_tick && git reset --hard HEAD~2 &&
111 test -f C &&
112 test -f A/B/E &&
113 ! test -f F &&
114 ! test -f A/G &&
116 check_have A B C D E F G H I J K L &&
118 git prune &&
120 check_have A B C D E F G H I J K L &&
122 loglen=$(wc -l <.git/logs/refs/heads/master) &&
123 test $loglen = 5
126 test_expect_success 'corrupt and check' '
128 corrupt $F &&
129 check_fsck "missing blob $F"
133 test_expect_success 'reflog expire --dry-run should not touch reflog' '
135 git reflog expire --dry-run \
136 --expire=$(($test_tick - 10000)) \
137 --expire-unreachable=$(($test_tick - 10000)) \
138 --stale-fix \
139 --all &&
141 loglen=$(wc -l <.git/logs/refs/heads/master) &&
142 test $loglen = 5 &&
144 check_fsck "missing blob $F"
147 test_expect_success 'reflog expire' '
149 git reflog expire --verbose \
150 --expire=$(($test_tick - 10000)) \
151 --expire-unreachable=$(($test_tick - 10000)) \
152 --stale-fix \
153 --all &&
155 loglen=$(wc -l <.git/logs/refs/heads/master) &&
156 test $loglen = 2 &&
158 check_fsck "dangling commit $K"
161 test_expect_success 'prune and fsck' '
163 git prune &&
164 check_fsck &&
166 check_have A B C D E H L &&
167 check_dont_have F G I J K
171 test_expect_success 'recover and check' '
173 recover $F &&
174 check_fsck "dangling blob $F"
178 test_done