t / t5501-fetch-push-alternates.shon commit Merge branch 'jh/checkout-auto-tracking' into maint (11fbc0b)
   1#!/bin/sh
   2
   3test_description='fetch/push involving alternates'
   4. ./test-lib.sh
   5
   6count_objects () {
   7        loose=0 inpack=0
   8        eval "$(
   9                git count-objects -v |
  10                sed -n -e 's/^count: \(.*\)/loose=\1/p' \
  11                    -e 's/^in-pack: \(.*\)/inpack=\1/p'
  12        )" &&
  13        echo $(( $loose + $inpack ))
  14}
  15
  16
  17test_expect_success setup '
  18        (
  19                git init original &&
  20                cd original &&
  21                i=0 &&
  22                while test $i -le 100
  23                do
  24                        echo "$i" >count &&
  25                        git add count &&
  26                        git commit -m "$i" || exit
  27                        i=$(($i + 1))
  28                done
  29        ) &&
  30        (
  31                git clone --reference=original "file://$(pwd)/original" one &&
  32                cd one &&
  33                echo Z >count &&
  34                git add count &&
  35                git commit -m Z &&
  36                count_objects >../one.count
  37        ) &&
  38        A=$(pwd)/original/.git/objects &&
  39        git init receiver &&
  40        echo "$A" >receiver/.git/objects/info/alternates &&
  41        git init fetcher &&
  42        echo "$A" >fetcher/.git/objects/info/alternates
  43'
  44
  45test_expect_success 'pushing into a repository with the same alternate' '
  46        (
  47                cd one &&
  48                git push ../receiver master:refs/heads/it
  49        ) &&
  50        (
  51                cd receiver &&
  52                count_objects >../receiver.count
  53        ) &&
  54        test_cmp one.count receiver.count
  55'
  56
  57test_expect_success 'fetching from a repository with the same alternate' '
  58        (
  59                cd fetcher &&
  60                git fetch ../one master:refs/heads/it &&
  61                count_objects >../fetcher.count
  62        ) &&
  63        test_cmp one.count fetcher.count
  64'
  65
  66test_done