t / t5502-quickfetch.shon commit Merge branch 'mz/rebase-abort-reflog-fix' (6b236bf)
   1#!/bin/sh
   2
   3test_description='test quickfetch from local'
   4
   5. ./test-lib.sh
   6
   7test_expect_success setup '
   8
   9        test_tick &&
  10        echo ichi >file &&
  11        git add file &&
  12        git commit -m initial &&
  13
  14        cnt=$( (
  15                git count-objects | sed -e "s/ *objects,.*//"
  16        ) ) &&
  17        test $cnt -eq 3
  18'
  19
  20test_expect_success 'clone without alternate' '
  21
  22        (
  23                mkdir cloned &&
  24                cd cloned &&
  25                git init-db &&
  26                git remote add -f origin ..
  27        ) &&
  28        cnt=$( (
  29                cd cloned &&
  30                git count-objects | sed -e "s/ *objects,.*//"
  31        ) ) &&
  32        test $cnt -eq 3
  33'
  34
  35test_expect_success 'further commits in the original' '
  36
  37        test_tick &&
  38        echo ni >file &&
  39        git commit -a -m second &&
  40
  41        cnt=$( (
  42                git count-objects | sed -e "s/ *objects,.*//"
  43        ) ) &&
  44        test $cnt -eq 6
  45'
  46
  47test_expect_success 'copy commit and tree but not blob by hand' '
  48
  49        git rev-list --objects HEAD |
  50        git pack-objects --stdout |
  51        (
  52                cd cloned &&
  53                git unpack-objects
  54        ) &&
  55
  56        cnt=$( (
  57                cd cloned &&
  58                git count-objects | sed -e "s/ *objects,.*//"
  59        ) ) &&
  60        test $cnt -eq 6 &&
  61
  62        blob=$(git rev-parse HEAD:file | sed -e "s|..|&/|") &&
  63        test -f "cloned/.git/objects/$blob" &&
  64        rm -f "cloned/.git/objects/$blob" &&
  65
  66        cnt=$( (
  67                cd cloned &&
  68                git count-objects | sed -e "s/ *objects,.*//"
  69        ) ) &&
  70        test $cnt -eq 5
  71
  72'
  73
  74test_expect_success 'quickfetch should not leave a corrupted repository' '
  75
  76        (
  77                cd cloned &&
  78                git fetch
  79        ) &&
  80
  81        cnt=$( (
  82                cd cloned &&
  83                git count-objects | sed -e "s/ *objects,.*//"
  84        ) ) &&
  85        test $cnt -eq 6
  86
  87'
  88
  89test_expect_success 'quickfetch should not copy from alternate' '
  90
  91        (
  92                mkdir quickclone &&
  93                cd quickclone &&
  94                git init-db &&
  95                (cd ../.git/objects && pwd) >.git/objects/info/alternates &&
  96                git remote add origin .. &&
  97                git fetch -k -k
  98        ) &&
  99        obj_cnt=$( (
 100                cd quickclone &&
 101                git count-objects | sed -e "s/ *objects,.*//"
 102        ) ) &&
 103        pck_cnt=$( (
 104                cd quickclone &&
 105                git count-objects -v | sed -n -e "/packs:/{
 106                                s/packs://
 107                                p
 108                                q
 109                        }"
 110        ) ) &&
 111        origin_master=$( (
 112                cd quickclone &&
 113                git rev-parse origin/master
 114        ) ) &&
 115        echo "loose objects: $obj_cnt, packfiles: $pck_cnt" &&
 116        test $obj_cnt -eq 0 &&
 117        test $pck_cnt -eq 0 &&
 118        test z$origin_master = z$(git rev-parse master)
 119
 120'
 121
 122test_expect_success 'quickfetch should handle ~1000 refs (on Windows)' '
 123
 124        git gc &&
 125        head=$(git rev-parse HEAD) &&
 126        branchprefix="$head refs/heads/branch" &&
 127        for i in 0 1 2 3 4 5 6 7 8 9; do
 128                for j in 0 1 2 3 4 5 6 7 8 9; do
 129                        for k in 0 1 2 3 4 5 6 7 8 9; do
 130                                echo "$branchprefix$i$j$k" >> .git/packed-refs
 131                        done
 132                done
 133        done &&
 134        (
 135                cd cloned &&
 136                git fetch &&
 137                git fetch
 138        )
 139
 140'
 141
 142test_done