t / t5304-prune.shon commit add basic http clone/fetch tests (119c8ee)
   1#!/bin/sh
   2#
   3# Copyright (c) 2008 Johannes E. Schindelin
   4#
   5
   6test_description='prune'
   7. ./test-lib.sh
   8
   9test_expect_success setup '
  10
  11        : > file &&
  12        git add file &&
  13        test_tick &&
  14        git commit -m initial &&
  15        git gc
  16
  17'
  18
  19test_expect_success 'prune stale packs' '
  20
  21        orig_pack=$(echo .git/objects/pack/*.pack) &&
  22        : > .git/objects/tmp_1.pack &&
  23        : > .git/objects/tmp_2.pack &&
  24        test-chmtime =-86501 .git/objects/tmp_1.pack &&
  25        git prune --expire 1.day &&
  26        test -f $orig_pack &&
  27        test -f .git/objects/tmp_2.pack &&
  28        ! test -f .git/objects/tmp_1.pack
  29
  30'
  31
  32test_expect_success 'prune --expire' '
  33
  34        before=$(git count-objects | sed "s/ .*//") &&
  35        BLOB=$(echo aleph | git hash-object -w --stdin) &&
  36        BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") &&
  37        test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
  38        test -f $BLOB_FILE &&
  39        git prune --expire=1.hour.ago &&
  40        test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
  41        test -f $BLOB_FILE &&
  42        test-chmtime =-86500 $BLOB_FILE &&
  43        git prune --expire 1.day &&
  44        test $before = $(git count-objects | sed "s/ .*//") &&
  45        ! test -f $BLOB_FILE
  46
  47'
  48
  49test_expect_success 'gc: implicit prune --expire' '
  50
  51        before=$(git count-objects | sed "s/ .*//") &&
  52        BLOB=$(echo aleph_0 | git hash-object -w --stdin) &&
  53        BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") &&
  54        test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
  55        test -f $BLOB_FILE &&
  56        test-chmtime =-$((86400*14-30)) $BLOB_FILE &&
  57        git gc &&
  58        test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
  59        test -f $BLOB_FILE &&
  60        test-chmtime =-$((86400*14+1)) $BLOB_FILE &&
  61        git gc &&
  62        test $before = $(git count-objects | sed "s/ .*//") &&
  63        ! test -f $BLOB_FILE
  64
  65'
  66
  67test_expect_success 'gc: refuse to start with invalid gc.pruneExpire' '
  68
  69        git config gc.pruneExpire invalid &&
  70        test_must_fail git gc
  71
  72'
  73
  74test_expect_success 'gc: start with ok gc.pruneExpire' '
  75
  76        git config gc.pruneExpire 2.days.ago &&
  77        git gc
  78
  79'
  80
  81test_expect_success 'prune: prune nonsense parameters' '
  82
  83        test_must_fail git prune garbage &&
  84        test_must_fail git prune --- &&
  85        test_must_fail git prune --no-such-option
  86
  87'
  88
  89test_expect_success 'prune: prune unreachable heads' '
  90
  91        git config core.logAllRefUpdates false &&
  92        mv .git/logs .git/logs.old &&
  93        : > file2 &&
  94        git add file2 &&
  95        git commit -m temporary &&
  96        tmp_head=$(git rev-list -1 HEAD) &&
  97        git reset HEAD^ &&
  98        git prune &&
  99        test_must_fail git reset $tmp_head --
 100
 101'
 102
 103test_expect_success 'prune: do not prune heads listed as an argument' '
 104
 105        : > file2 &&
 106        git add file2 &&
 107        git commit -m temporary &&
 108        tmp_head=$(git rev-list -1 HEAD) &&
 109        git reset HEAD^ &&
 110        git prune -- $tmp_head &&
 111        git reset $tmp_head --
 112
 113'
 114
 115test_expect_success 'gc --no-prune' '
 116
 117        before=$(git count-objects | sed "s/ .*//") &&
 118        BLOB=$(echo aleph_0 | git hash-object -w --stdin) &&
 119        BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") &&
 120        test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
 121        test -f $BLOB_FILE &&
 122        test-chmtime =-$((86400*5001)) $BLOB_FILE &&
 123        git config gc.pruneExpire 2.days.ago &&
 124        git gc --no-prune &&
 125        test 1 = $(git count-objects | sed "s/ .*//") &&
 126        test -f $BLOB_FILE
 127
 128'
 129
 130test_expect_success 'gc respects gc.pruneExpire' '
 131
 132        git config gc.pruneExpire 5002.days.ago &&
 133        git gc &&
 134        test -f $BLOB_FILE &&
 135        git config gc.pruneExpire 5000.days.ago &&
 136        git gc &&
 137        test ! -f $BLOB_FILE
 138
 139'
 140
 141test_expect_success 'gc --prune=<date>' '
 142
 143        BLOB=$(echo aleph_0 | git hash-object -w --stdin) &&
 144        BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") &&
 145        test-chmtime =-$((86400*5001)) $BLOB_FILE &&
 146        git gc --prune=5002.days.ago &&
 147        test -f $BLOB_FILE &&
 148        git gc --prune=5000.days.ago &&
 149        test ! -f $BLOB_FILE
 150
 151'
 152
 153test_done