t / t5304-prune.shon commit Add global and system-wide gitattributes (6df42ab)
   1#!/bin/sh
   2#
   3# Copyright (c) 2008 Johannes E. Schindelin
   4#
   5
   6test_description='prune'
   7. ./test-lib.sh
   8
   9day=$((60*60*24))
  10week=$(($day*7))
  11
  12add_blob() {
  13        before=$(git count-objects | sed "s/ .*//") &&
  14        BLOB=$(echo aleph_0 | git hash-object -w --stdin) &&
  15        BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") &&
  16        test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
  17        test -f $BLOB_FILE
  18}
  19
  20test_expect_success setup '
  21
  22        : > file &&
  23        git add file &&
  24        test_tick &&
  25        git commit -m initial &&
  26        git gc
  27
  28'
  29
  30test_expect_success 'prune stale packs' '
  31
  32        orig_pack=$(echo .git/objects/pack/*.pack) &&
  33        : > .git/objects/tmp_1.pack &&
  34        : > .git/objects/tmp_2.pack &&
  35        test-chmtime =-86501 .git/objects/tmp_1.pack &&
  36        git prune --expire 1.day &&
  37        test -f $orig_pack &&
  38        test -f .git/objects/tmp_2.pack &&
  39        ! test -f .git/objects/tmp_1.pack
  40
  41'
  42
  43test_expect_success 'prune --expire' '
  44
  45        add_blob &&
  46        git prune --expire=1.hour.ago &&
  47        test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
  48        test -f $BLOB_FILE &&
  49        test-chmtime =-86500 $BLOB_FILE &&
  50        git prune --expire 1.day &&
  51        test $before = $(git count-objects | sed "s/ .*//") &&
  52        ! test -f $BLOB_FILE
  53
  54'
  55
  56test_expect_success 'gc: implicit prune --expire' '
  57
  58        add_blob &&
  59        test-chmtime =-$((2*$week-30)) $BLOB_FILE &&
  60        git gc &&
  61        test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
  62        test -f $BLOB_FILE &&
  63        test-chmtime =-$((2*$week+1)) $BLOB_FILE &&
  64        git gc &&
  65        test $before = $(git count-objects | sed "s/ .*//") &&
  66        ! test -f $BLOB_FILE
  67
  68'
  69
  70test_expect_success 'gc: refuse to start with invalid gc.pruneExpire' '
  71
  72        git config gc.pruneExpire invalid &&
  73        test_must_fail git gc
  74
  75'
  76
  77test_expect_success 'gc: start with ok gc.pruneExpire' '
  78
  79        git config gc.pruneExpire 2.days.ago &&
  80        git gc
  81
  82'
  83
  84test_expect_success 'prune: prune nonsense parameters' '
  85
  86        test_must_fail git prune garbage &&
  87        test_must_fail git prune --- &&
  88        test_must_fail git prune --no-such-option
  89
  90'
  91
  92test_expect_success 'prune: prune unreachable heads' '
  93
  94        git config core.logAllRefUpdates false &&
  95        mv .git/logs .git/logs.old &&
  96        : > file2 &&
  97        git add file2 &&
  98        git commit -m temporary &&
  99        tmp_head=$(git rev-list -1 HEAD) &&
 100        git reset HEAD^ &&
 101        git prune &&
 102        test_must_fail git reset $tmp_head --
 103
 104'
 105
 106test_expect_success 'prune: do not prune heads listed as an argument' '
 107
 108        : > file2 &&
 109        git add file2 &&
 110        git commit -m temporary &&
 111        tmp_head=$(git rev-list -1 HEAD) &&
 112        git reset HEAD^ &&
 113        git prune -- $tmp_head &&
 114        git reset $tmp_head --
 115
 116'
 117
 118test_expect_success 'gc --no-prune' '
 119
 120        add_blob &&
 121        test-chmtime =-$((5001*$day)) $BLOB_FILE &&
 122        git config gc.pruneExpire 2.days.ago &&
 123        git gc --no-prune &&
 124        test 1 = $(git count-objects | sed "s/ .*//") &&
 125        test -f $BLOB_FILE
 126
 127'
 128
 129test_expect_success 'gc respects gc.pruneExpire' '
 130
 131        git config gc.pruneExpire 5002.days.ago &&
 132        git gc &&
 133        test -f $BLOB_FILE &&
 134        git config gc.pruneExpire 5000.days.ago &&
 135        git gc &&
 136        test ! -f $BLOB_FILE
 137
 138'
 139
 140test_expect_success 'gc --prune=<date>' '
 141
 142        add_blob &&
 143        test-chmtime =-$((5001*$day)) $BLOB_FILE &&
 144        git gc --prune=5002.days.ago &&
 145        test -f $BLOB_FILE &&
 146        git gc --prune=5000.days.ago &&
 147        test ! -f $BLOB_FILE
 148
 149'
 150
 151test_expect_success 'gc --prune=never' '
 152
 153        add_blob &&
 154        git gc --prune=never &&
 155        test -f $BLOB_FILE &&
 156        git gc --prune=now &&
 157        test ! -f $BLOB_FILE
 158
 159'
 160
 161test_expect_success 'gc respects gc.pruneExpire=never' '
 162
 163        git config gc.pruneExpire never &&
 164        add_blob &&
 165        git gc &&
 166        test -f $BLOB_FILE &&
 167        git config gc.pruneExpire now &&
 168        git gc &&
 169        test ! -f $BLOB_FILE
 170
 171'
 172
 173test_expect_success 'prune --expire=never' '
 174
 175        add_blob &&
 176        git prune --expire=never &&
 177        test -f $BLOB_FILE &&
 178        git prune &&
 179        test ! -f $BLOB_FILE
 180
 181'
 182
 183test_expect_success 'gc: prune old objects after local clone' '
 184        add_blob &&
 185        test-chmtime =-$((2*$week+1)) $BLOB_FILE &&
 186        git clone --no-hardlinks . aclone &&
 187        (
 188                cd aclone &&
 189                test 1 = $(git count-objects | sed "s/ .*//") &&
 190                test -f $BLOB_FILE &&
 191                git gc --prune &&
 192                test 0 = $(git count-objects | sed "s/ .*//") &&
 193                ! test -f $BLOB_FILE
 194        )
 195'
 196
 197test_done