t / t5304-prune.shon commit difftool: print list of valid tools with '--tool-help' (bf73fc2)
   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        test-chmtime =+0 $BLOB_FILE
  19}
  20
  21test_expect_success setup '
  22
  23        : > file &&
  24        git add file &&
  25        test_tick &&
  26        git commit -m initial &&
  27        git gc
  28
  29'
  30
  31test_expect_success 'prune stale packs' '
  32
  33        orig_pack=$(echo .git/objects/pack/*.pack) &&
  34        : > .git/objects/tmp_1.pack &&
  35        : > .git/objects/tmp_2.pack &&
  36        test-chmtime =-86501 .git/objects/tmp_1.pack &&
  37        git prune --expire 1.day &&
  38        test -f $orig_pack &&
  39        test -f .git/objects/tmp_2.pack &&
  40        ! test -f .git/objects/tmp_1.pack
  41
  42'
  43
  44test_expect_success 'prune --expire' '
  45
  46        add_blob &&
  47        git prune --expire=1.hour.ago &&
  48        test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
  49        test -f $BLOB_FILE &&
  50        test-chmtime =-86500 $BLOB_FILE &&
  51        git prune --expire 1.day &&
  52        test $before = $(git count-objects | sed "s/ .*//") &&
  53        ! test -f $BLOB_FILE
  54
  55'
  56
  57test_expect_success 'gc: implicit prune --expire' '
  58
  59        add_blob &&
  60        test-chmtime =-$((2*$week-30)) $BLOB_FILE &&
  61        git gc &&
  62        test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
  63        test -f $BLOB_FILE &&
  64        test-chmtime =-$((2*$week+1)) $BLOB_FILE &&
  65        git gc &&
  66        test $before = $(git count-objects | sed "s/ .*//") &&
  67        ! test -f $BLOB_FILE
  68
  69'
  70
  71test_expect_success 'gc: refuse to start with invalid gc.pruneExpire' '
  72
  73        git config gc.pruneExpire invalid &&
  74        test_must_fail git gc
  75
  76'
  77
  78test_expect_success 'gc: start with ok gc.pruneExpire' '
  79
  80        git config gc.pruneExpire 2.days.ago &&
  81        git gc
  82
  83'
  84
  85test_expect_success 'prune: prune nonsense parameters' '
  86
  87        test_must_fail git prune garbage &&
  88        test_must_fail git prune --- &&
  89        test_must_fail git prune --no-such-option
  90
  91'
  92
  93test_expect_success 'prune: prune unreachable heads' '
  94
  95        git config core.logAllRefUpdates false &&
  96        mv .git/logs .git/logs.old &&
  97        : > file2 &&
  98        git add file2 &&
  99        git commit -m temporary &&
 100        tmp_head=$(git rev-list -1 HEAD) &&
 101        git reset HEAD^ &&
 102        git prune &&
 103        test_must_fail git reset $tmp_head --
 104
 105'
 106
 107test_expect_success 'prune: do not prune heads listed as an argument' '
 108
 109        : > file2 &&
 110        git add file2 &&
 111        git commit -m temporary &&
 112        tmp_head=$(git rev-list -1 HEAD) &&
 113        git reset HEAD^ &&
 114        git prune -- $tmp_head &&
 115        git reset $tmp_head --
 116
 117'
 118
 119test_expect_success 'gc --no-prune' '
 120
 121        add_blob &&
 122        test-chmtime =-$((5001*$day)) $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        add_blob &&
 144        test-chmtime =-$((5001*$day)) $BLOB_FILE &&
 145        git gc --prune=5002.days.ago &&
 146        test -f $BLOB_FILE &&
 147        git gc --prune=5000.days.ago &&
 148        test ! -f $BLOB_FILE
 149
 150'
 151
 152test_expect_success 'gc --prune=never' '
 153
 154        add_blob &&
 155        git gc --prune=never &&
 156        test -f $BLOB_FILE &&
 157        git gc --prune=now &&
 158        test ! -f $BLOB_FILE
 159
 160'
 161
 162test_expect_success 'gc respects gc.pruneExpire=never' '
 163
 164        git config gc.pruneExpire never &&
 165        add_blob &&
 166        git gc &&
 167        test -f $BLOB_FILE &&
 168        git config gc.pruneExpire now &&
 169        git gc &&
 170        test ! -f $BLOB_FILE
 171
 172'
 173
 174test_expect_success 'prune --expire=never' '
 175
 176        add_blob &&
 177        git prune --expire=never &&
 178        test -f $BLOB_FILE &&
 179        git prune &&
 180        test ! -f $BLOB_FILE
 181
 182'
 183
 184test_expect_success 'gc: prune old objects after local clone' '
 185        add_blob &&
 186        test-chmtime =-$((2*$week+1)) $BLOB_FILE &&
 187        git clone --no-hardlinks . aclone &&
 188        (
 189                cd aclone &&
 190                test 1 = $(git count-objects | sed "s/ .*//") &&
 191                test -f $BLOB_FILE &&
 192                git gc --prune &&
 193                test 0 = $(git count-objects | sed "s/ .*//") &&
 194                ! test -f $BLOB_FILE
 195        )
 196'
 197
 198test_done