t / t5537-fetch-shallow.shon commit fetch: support fetching from a shallow repository (4820a33)
   1#!/bin/sh
   2
   3test_description='fetch/clone from a shallow clone'
   4
   5. ./test-lib.sh
   6
   7commit() {
   8        echo "$1" >tracked &&
   9        git add tracked &&
  10        git commit -m "$1"
  11}
  12
  13test_expect_success 'setup' '
  14        commit 1 &&
  15        commit 2 &&
  16        commit 3 &&
  17        commit 4 &&
  18        git config --global transfer.fsckObjects true
  19'
  20
  21test_expect_success 'setup shallow clone' '
  22        git clone --no-local --depth=2 .git shallow &&
  23        git --git-dir=shallow/.git log --format=%s >actual &&
  24        cat <<EOF >expect &&
  254
  263
  27EOF
  28        test_cmp expect actual
  29'
  30
  31test_expect_success 'clone from shallow clone' '
  32        git clone --no-local shallow shallow2 &&
  33        (
  34        cd shallow2 &&
  35        git fsck &&
  36        git log --format=%s >actual &&
  37        cat <<EOF >expect &&
  384
  393
  40EOF
  41        test_cmp expect actual
  42        )
  43'
  44
  45test_expect_success 'fetch from shallow clone' '
  46        (
  47        cd shallow &&
  48        commit 5
  49        ) &&
  50        (
  51        cd shallow2 &&
  52        git fetch &&
  53        git fsck &&
  54        git log --format=%s origin/master >actual &&
  55        cat <<EOF >expect &&
  565
  574
  583
  59EOF
  60        test_cmp expect actual
  61        )
  62'
  63
  64test_expect_success 'fetch --depth from shallow clone' '
  65        (
  66        cd shallow &&
  67        commit 6
  68        ) &&
  69        (
  70        cd shallow2 &&
  71        git fetch --depth=2 &&
  72        git fsck &&
  73        git log --format=%s origin/master >actual &&
  74        cat <<EOF >expect &&
  756
  765
  77EOF
  78        test_cmp expect actual
  79        )
  80'
  81
  82test_expect_success 'fetch something upstream has but hidden by clients shallow boundaries' '
  83        # the blob "1" is available in .git but hidden by the
  84        # shallow2/.git/shallow and it should be resent
  85        ! git --git-dir=shallow2/.git cat-file blob `echo 1|git hash-object --stdin` >/dev/null &&
  86        echo 1 >1.t &&
  87        git add 1.t &&
  88        git commit -m add-1-back &&
  89        (
  90        cd shallow2 &&
  91        git fetch ../.git +refs/heads/master:refs/remotes/top/master &&
  92        git fsck &&
  93        git log --format=%s top/master >actual &&
  94        cat <<EOF >expect &&
  95add-1-back
  964
  973
  98EOF
  99        test_cmp expect actual
 100        ) &&
 101        git --git-dir=shallow2/.git cat-file blob `echo 1|git hash-object --stdin` >/dev/null
 102
 103'
 104
 105test_expect_success 'fetch that requires changes in .git/shallow is filtered' '
 106        (
 107        cd shallow &&
 108        git checkout --orphan no-shallow &&
 109        commit no-shallow
 110        ) &&
 111        git init notshallow &&
 112        (
 113        cd notshallow &&
 114        git fetch ../shallow/.git refs/heads/*:refs/remotes/shallow/*&&
 115        git for-each-ref --format="%(refname)" >actual.refs &&
 116        cat <<EOF >expect.refs &&
 117refs/remotes/shallow/no-shallow
 118EOF
 119        test_cmp expect.refs actual.refs &&
 120        git log --format=%s shallow/no-shallow >actual &&
 121        cat <<EOF >expect &&
 122no-shallow
 123EOF
 124        test_cmp expect actual
 125        )
 126'
 127
 128test_done