FYI: Reply from HP-UX
[git/dscho.git] / t / t1410-reflog.sh
blob0afc3d4a620de8df6ac6b426b07c62ef691291f4
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_done
58 exit
60 test_expect_success setup '
61 mkdir -p A/B &&
62 echo rat >C &&
63 echo ox >A/D &&
64 echo tiger >A/B/E &&
65 git add . &&
67 test_tick && git commit -m rabbit &&
68 H=`git rev-parse --verify HEAD` &&
69 A=`git rev-parse --verify HEAD:A` &&
70 B=`git rev-parse --verify HEAD:A/B` &&
71 C=`git rev-parse --verify HEAD:C` &&
72 D=`git rev-parse --verify HEAD:A/D` &&
73 E=`git rev-parse --verify HEAD:A/B/E` &&
74 check_fsck &&
76 chmod +x C &&
77 ( test "`git config --bool core.filemode`" != false ||
78 echo executable >>C ) &&
79 git add C &&
80 test_tick && git commit -m dragon &&
81 L=`git rev-parse --verify HEAD` &&
82 check_fsck &&
84 rm -f C A/B/E &&
85 echo snake >F &&
86 echo horse >A/G &&
87 git add F A/G &&
88 test_tick && git commit -a -m sheep &&
89 F=`git rev-parse --verify HEAD:F` &&
90 G=`git rev-parse --verify HEAD:A/G` &&
91 I=`git rev-parse --verify HEAD:A` &&
92 J=`git rev-parse --verify HEAD` &&
93 check_fsck &&
95 rm -f A/G &&
96 test_tick && git commit -a -m monkey &&
97 K=`git rev-parse --verify HEAD` &&
98 check_fsck &&
100 check_have A B C D E F G H I J K L &&
102 git prune &&
104 check_have A B C D E F G H I J K L &&
106 check_fsck &&
108 loglen=$(wc -l <.git/logs/refs/heads/master) &&
109 test $loglen = 4
112 test_expect_success rewind '
113 test_tick && git reset --hard HEAD~2 &&
114 test -f C &&
115 test -f A/B/E &&
116 ! test -f F &&
117 ! test -f A/G &&
119 check_have A B C D E F G H I J K L &&
121 git prune &&
123 check_have A B C D E F G H I J K L &&
125 loglen=$(wc -l <.git/logs/refs/heads/master) &&
126 test $loglen = 5
129 test_expect_success 'corrupt and check' '
131 corrupt $F &&
132 check_fsck "missing blob $F"
136 test_expect_success 'reflog expire --dry-run should not touch reflog' '
138 git reflog expire --dry-run \
139 --expire=$(($test_tick - 10000)) \
140 --expire-unreachable=$(($test_tick - 10000)) \
141 --stale-fix \
142 --all &&
144 loglen=$(wc -l <.git/logs/refs/heads/master) &&
145 test $loglen = 5 &&
147 check_fsck "missing blob $F"
150 test_expect_success 'reflog expire' '
152 git reflog expire --verbose \
153 --expire=$(($test_tick - 10000)) \
154 --expire-unreachable=$(($test_tick - 10000)) \
155 --stale-fix \
156 --all &&
158 loglen=$(wc -l <.git/logs/refs/heads/master) &&
159 test $loglen = 2 &&
161 check_fsck "dangling commit $K"
164 test_expect_success 'prune and fsck' '
166 git prune &&
167 check_fsck &&
169 check_have A B C D E H L &&
170 check_dont_have F G I J K
174 test_expect_success 'recover and check' '
176 recover $F &&
177 check_fsck "dangling blob $F"
181 test_done