Code

Merge commit 'v1.6.0' into jc/checkout-reflog-fix
[git.git] / t / t1410-reflog.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Junio C Hamano
4 #
6 test_description='Test prune and reflog expiration'
7 . ./test-lib.sh
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 }
22 check_fsck () {
23         output=$(git fsck --full)
24         case "$1" in
25         '')
26                 test -z "$output" ;;
27         *)
28                 echo "$output" | grep "$1" ;;
29         esac
30 }
32 corrupt () {
33         aa=${1%??????????????????????????????????????} zz=${1#??}
34         mv .git/objects/$aa/$zz .git/$aa$zz
35 }
37 recover () {
38         aa=${1%??????????????????????????????????????} zz=${1#??}
39         mkdir -p .git/objects/$aa
40         mv .git/$aa$zz .git/objects/$aa/$zz
41 }
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 }
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_expect_success 'delete' '
179         echo 1 > C &&
180         test_tick &&
181         git commit -m rat C &&
183         echo 2 > C &&
184         test_tick &&
185         git commit -m ox C &&
187         echo 3 > C &&
188         test_tick &&
189         git commit -m tiger C &&
191         HEAD_entry_count=$(git reflog | wc -l)
192         master_entry_count=$(git reflog show master | wc -l)
194         test $HEAD_entry_count = 5 &&
195         test $master_entry_count = 5 &&
198         git reflog delete master@{1} &&
199         git reflog show master > output &&
200         test $(($master_entry_count - 1)) = $(wc -l < output) &&
201         test $HEAD_entry_count = $(git reflog | wc -l) &&
202         ! grep ox < output &&
204         master_entry_count=$(wc -l < output)
206         git reflog delete HEAD@{1} &&
207         test $(($HEAD_entry_count -1)) = $(git reflog | wc -l) &&
208         test $master_entry_count = $(git reflog show master | wc -l) &&
210         HEAD_entry_count=$(git reflog | wc -l)
212         git reflog delete master@{07.04.2005.15:15:00.-0700} &&
213         git reflog show master > output &&
214         test $(($master_entry_count - 1)) = $(wc -l < output) &&
215         ! grep dragon < output
219 test_done