t / t7700-repack.shon commit grep: --name-only over binary (321ffcc)
   1#!/bin/sh
   2
   3test_description='git repack works correctly'
   4
   5. ./test-lib.sh
   6
   7test_expect_success 'objects in packs marked .keep are not repacked' '
   8        echo content1 > file1 &&
   9        echo content2 > file2 &&
  10        git add . &&
  11        git commit -m initial_commit &&
  12        # Create two packs
  13        # The first pack will contain all of the objects except one
  14        git rev-list --objects --all | grep -v file2 |
  15                git pack-objects pack > /dev/null &&
  16        # The second pack will contain the excluded object
  17        packsha1=$(git rev-list --objects --all | grep file2 |
  18                git pack-objects pack) &&
  19        touch -r pack-$packsha1.pack pack-$packsha1.keep &&
  20        objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 |
  21                sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
  22        mv pack-* .git/objects/pack/ &&
  23        git repack -A -d -l &&
  24        git prune-packed &&
  25        for p in .git/objects/pack/*.idx; do
  26                idx=$(basename $p)
  27                test "pack-$packsha1.idx" = "$idx" && continue
  28                if git verify-pack -v $p | egrep "^$objsha1"; then
  29                        found_duplicate_object=1
  30                        echo "DUPLICATE OBJECT FOUND"
  31                        break
  32                fi
  33        done &&
  34        test -z "$found_duplicate_object"
  35'
  36
  37test_expect_success 'loose objects in alternate ODB are not repacked' '
  38        mkdir alt_objects &&
  39        echo `pwd`/alt_objects > .git/objects/info/alternates &&
  40        echo content3 > file3 &&
  41        objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
  42        git add file3 &&
  43        git commit -m commit_file3 &&
  44        git repack -a -d -l &&
  45        git prune-packed &&
  46        for p in .git/objects/pack/*.idx; do
  47                if git verify-pack -v $p | egrep "^$objsha1"; then
  48                        found_duplicate_object=1
  49                        echo "DUPLICATE OBJECT FOUND"
  50                        break
  51                fi
  52        done &&
  53        test -z "$found_duplicate_object"
  54'
  55
  56test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' '
  57        mkdir alt_objects/pack
  58        mv .git/objects/pack/* alt_objects/pack &&
  59        git repack -a &&
  60        myidx=$(ls -1 .git/objects/pack/*.idx) &&
  61        test -f "$myidx" &&
  62        for p in alt_objects/pack/*.idx; do
  63                git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
  64        done | while read sha1 rest; do
  65                if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
  66                        echo "Missing object in local pack: $sha1"
  67                        return 1
  68                fi
  69        done
  70'
  71
  72test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
  73        rm -f .git/objects/pack/* &&
  74        echo new_content >> file1 &&
  75        git add file1 &&
  76        git commit -m more_content &&
  77        git repack &&
  78        git repack -a -d &&
  79        myidx=$(ls -1 .git/objects/pack/*.idx) &&
  80        test -f "$myidx" &&
  81        for p in alt_objects/pack/*.idx; do
  82                git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
  83        done | while read sha1 rest; do
  84                if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
  85                        echo "Missing object in local pack: $sha1"
  86                        return 1
  87                fi
  88        done
  89'
  90
  91test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
  92        # swap the .keep so the commit object is in the pack with .keep
  93        for p in alt_objects/pack/*.pack
  94        do
  95                base_name=$(basename $p .pack)
  96                if test -f alt_objects/pack/$base_name.keep
  97                then
  98                        rm alt_objects/pack/$base_name.keep
  99                else
 100                        touch alt_objects/pack/$base_name.keep
 101                fi
 102        done
 103        git repack -a -d &&
 104        myidx=$(ls -1 .git/objects/pack/*.idx) &&
 105        test -f "$myidx" &&
 106        for p in alt_objects/pack/*.idx; do
 107                git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
 108        done | while read sha1 rest; do
 109                if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
 110                        echo "Missing object in local pack: $sha1"
 111                        return 1
 112                fi
 113        done
 114'
 115
 116test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
 117        rm -f alt_objects/pack/*.keep &&
 118        mv .git/objects/pack/* alt_objects/pack/ &&
 119        csha1=$(git rev-parse HEAD^{commit}) &&
 120        git reset --hard HEAD^ &&
 121        sleep 1 &&
 122        git reflog expire --expire=now --expire-unreachable=now --all &&
 123        # The pack-objects call on the next line is equivalent to
 124        # git repack -A -d without the call to prune-packed
 125        git pack-objects --honor-pack-keep --non-empty --all --reflog \
 126            --unpack-unreachable </dev/null pack &&
 127        rm -f .git/objects/pack/* &&
 128        mv pack-* .git/objects/pack/ &&
 129        test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
 130                egrep "^$csha1 " | sort | uniq | wc -l) &&
 131        echo > .git/objects/info/alternates &&
 132        test_must_fail git show $csha1
 133'
 134
 135test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' '
 136        echo `pwd`/alt_objects > .git/objects/info/alternates &&
 137        echo "$csha1" | git pack-objects --non-empty --all --reflog pack &&
 138        rm -f .git/objects/pack/* &&
 139        mv pack-* .git/objects/pack/ &&
 140        # The pack-objects call on the next line is equivalent to
 141        # git repack -A -d without the call to prune-packed
 142        git pack-objects --honor-pack-keep --non-empty --all --reflog \
 143            --unpack-unreachable </dev/null pack &&
 144        rm -f .git/objects/pack/* &&
 145        mv pack-* .git/objects/pack/ &&
 146        test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
 147                egrep "^$csha1 " | sort | uniq | wc -l) &&
 148        echo > .git/objects/info/alternates &&
 149        test_must_fail git show $csha1
 150'
 151
 152test_expect_success 'objects made unreachable by grafts only are kept' '
 153        test_tick &&
 154        git commit --allow-empty -m "commit 4" &&
 155        H0=$(git rev-parse HEAD) &&
 156        H1=$(git rev-parse HEAD^) &&
 157        H2=$(git rev-parse HEAD^^) &&
 158        echo "$H0 $H2" > .git/info/grafts &&
 159        git reflog expire --expire=now --expire-unreachable=now --all &&
 160        git repack -a -d &&
 161        git cat-file -t $H1
 162        '
 163
 164test_done
 165