t / t1410-reflog.shon commit Merge branch 'maint-1.7.11' into maint (e3f2675)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Junio C Hamano
   4#
   5
   6test_description='Test prune and reflog expiration'
   7. ./test-lib.sh
   8
   9check_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
  22check_fsck () {
  23        output=$(git fsck --full)
  24        case "$1" in
  25        '')
  26                test -z "$output" ;;
  27        *)
  28                echo "$output" | grep "$1" ;;
  29        esac
  30}
  31
  32corrupt () {
  33        aa=${1%??????????????????????????????????????} zz=${1#??}
  34        mv .git/objects/$aa/$zz .git/$aa$zz
  35}
  36
  37recover () {
  38        aa=${1%??????????????????????????????????????} zz=${1#??}
  39        mkdir -p .git/objects/$aa
  40        mv .git/$aa$zz .git/objects/$aa/$zz
  41}
  42
  43check_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
  57test_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
  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 &&
  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
  97        git prune &&
  98
  99        check_have A B C D E F G H I J K L &&
 100
 101        check_fsck &&
 102
 103        test_line_count = 4 .git/logs/refs/heads/master
 104'
 105
 106test_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 &&
 112
 113        check_have A B C D E F G H I J K L &&
 114
 115        git prune &&
 116
 117        check_have A B C D E F G H I J K L &&
 118
 119        test_line_count = 5 .git/logs/refs/heads/master
 120'
 121
 122test_expect_success 'corrupt and check' '
 123
 124        corrupt $F &&
 125        check_fsck "missing blob $F"
 126
 127'
 128
 129test_expect_success 'reflog expire --dry-run should not touch reflog' '
 130
 131        git reflog expire --dry-run \
 132                --expire=$(($test_tick - 10000)) \
 133                --expire-unreachable=$(($test_tick - 10000)) \
 134                --stale-fix \
 135                --all &&
 136
 137        test_line_count = 5 .git/logs/refs/heads/master &&
 138
 139        check_fsck "missing blob $F"
 140'
 141
 142test_expect_success 'reflog expire' '
 143
 144        git reflog expire --verbose \
 145                --expire=$(($test_tick - 10000)) \
 146                --expire-unreachable=$(($test_tick - 10000)) \
 147                --stale-fix \
 148                --all &&
 149
 150        test_line_count = 2 .git/logs/refs/heads/master &&
 151
 152        check_fsck "dangling commit $K"
 153'
 154
 155test_expect_success 'prune and fsck' '
 156
 157        git prune &&
 158        check_fsck &&
 159
 160        check_have A B C D E H L &&
 161        check_dont_have F G I J K
 162
 163'
 164
 165test_expect_success 'recover and check' '
 166
 167        recover $F &&
 168        check_fsck "dangling blob $F"
 169
 170'
 171
 172test_expect_success 'delete' '
 173        echo 1 > C &&
 174        test_tick &&
 175        git commit -m rat C &&
 176
 177        echo 2 > C &&
 178        test_tick &&
 179        git commit -m ox C &&
 180
 181        echo 3 > C &&
 182        test_tick &&
 183        git commit -m tiger C &&
 184
 185        HEAD_entry_count=$(git reflog | wc -l) &&
 186        master_entry_count=$(git reflog show master | wc -l) &&
 187
 188        test $HEAD_entry_count = 5 &&
 189        test $master_entry_count = 5 &&
 190
 191
 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 &&
 197
 198        master_entry_count=$(wc -l < output) &&
 199
 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) &&
 203
 204        HEAD_entry_count=$(git reflog | wc -l) &&
 205
 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
 210
 211'
 212
 213test_expect_success 'rewind2' '
 214
 215        test_tick && git reset --hard HEAD~2 &&
 216        test_line_count = 4 .git/logs/refs/heads/master
 217'
 218
 219test_expect_success '--expire=never' '
 220
 221        git reflog expire --verbose \
 222                --expire=never \
 223                --expire-unreachable=never \
 224                --all &&
 225        test_line_count = 4 .git/logs/refs/heads/master
 226'
 227
 228test_expect_success 'gc.reflogexpire=never' '
 229
 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
 234'
 235
 236test_expect_success 'gc.reflogexpire=false' '
 237
 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 &&
 242
 243        git config --unset gc.reflogexpire &&
 244        git config --unset gc.reflogexpireunreachable
 245
 246'
 247
 248test_done