t / t7701-repack-unpack-unreachable.shon commit color-words: take an optional regular expression describing words (2b6a541)
   1#!/bin/sh
   2
   3test_description='git repack works correctly'
   4
   5. ./test-lib.sh
   6
   7fsha1=
   8csha1=
   9tsha1=
  10
  11test_expect_success '-A with -d option leaves unreachable objects unpacked' '
  12        echo content > file1 &&
  13        git add . &&
  14        git commit -m initial_commit &&
  15        # create a transient branch with unique content
  16        git checkout -b transient_branch &&
  17        echo more content >> file1 &&
  18        # record the objects created in the database for file, commit, tree
  19        fsha1=$(git hash-object file1) &&
  20        git commit -a -m more_content &&
  21        csha1=$(git rev-parse HEAD^{commit}) &&
  22        tsha1=$(git rev-parse HEAD^{tree}) &&
  23        git checkout master &&
  24        echo even more content >> file1 &&
  25        git commit -a -m even_more_content &&
  26        # delete the transient branch
  27        git branch -D transient_branch &&
  28        # pack the repo
  29        git repack -A -d -l &&
  30        # verify objects are packed in repository
  31        test 3 = $(git verify-pack -v -- .git/objects/pack/*.idx |
  32                   egrep "^($fsha1|$csha1|$tsha1) " |
  33                   sort | uniq | wc -l) &&
  34        git show $fsha1 &&
  35        git show $csha1 &&
  36        git show $tsha1 &&
  37        # now expire the reflog
  38        sleep 1 &&
  39        git reflog expire --expire-unreachable=now --all &&
  40        # and repack
  41        git repack -A -d -l &&
  42        # verify objects are retained unpacked
  43        test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
  44                   egrep "^($fsha1|$csha1|$tsha1) " |
  45                   sort | uniq | wc -l) &&
  46        git show $fsha1 &&
  47        git show $csha1 &&
  48        git show $tsha1
  49'
  50
  51compare_mtimes ()
  52{
  53        perl -e 'my $reference = shift;
  54                 foreach my $file (@ARGV) {
  55                        exit(1) unless(-f $file && -M $file == -M $reference);
  56                 }
  57                 exit(0);
  58                ' -- "$@"
  59}
  60
  61test_expect_success '-A without -d option leaves unreachable objects packed' '
  62        fsha1path=$(echo "$fsha1" | sed -e "s|\(..\)|\1/|") &&
  63        fsha1path=".git/objects/$fsha1path" &&
  64        csha1path=$(echo "$csha1" | sed -e "s|\(..\)|\1/|") &&
  65        csha1path=".git/objects/$csha1path" &&
  66        tsha1path=$(echo "$tsha1" | sed -e "s|\(..\)|\1/|") &&
  67        tsha1path=".git/objects/$tsha1path" &&
  68        git branch transient_branch $csha1 &&
  69        git repack -a -d -l &&
  70        test ! -f "$fsha1path" &&
  71        test ! -f "$csha1path" &&
  72        test ! -f "$tsha1path" &&
  73        test 1 = $(ls -1 .git/objects/pack/pack-*.pack | wc -l) &&
  74        packfile=$(ls .git/objects/pack/pack-*.pack) &&
  75        git branch -D transient_branch &&
  76        sleep 1 &&
  77        git repack -A -l &&
  78        test ! -f "$fsha1path" &&
  79        test ! -f "$csha1path" &&
  80        test ! -f "$tsha1path" &&
  81        git show $fsha1 &&
  82        git show $csha1 &&
  83        git show $tsha1
  84'
  85
  86test_expect_success 'unpacked objects receive timestamp of pack file' '
  87        tmppack=".git/objects/pack/tmp_pack" &&
  88        ln "$packfile" "$tmppack" &&
  89        git repack -A -l -d &&
  90        compare_mtimes "$tmppack" "$fsha1path" "$csha1path" "$tsha1path"
  91'
  92
  93test_done