f5c74e6b34946179ee3fc5aaba5ed92ba3acc599
   1#!/bin/sh
   2
   3test_description='push from/to 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        git config --global transfer.fsckObjects true &&
  15        commit 1 &&
  16        commit 2 &&
  17        commit 3 &&
  18        commit 4 &&
  19        (
  20        git init full-abc &&
  21        cd full-abc &&
  22        commit a &&
  23        commit b &&
  24        commit c
  25        ) &&
  26        git clone --no-local --depth=2 .git shallow &&
  27        git --git-dir=shallow/.git log --format=%s >actual &&
  28        cat <<EOF >expect &&
  294
  303
  31EOF
  32        test_cmp expect actual &&
  33        git clone --no-local --depth=2 full-abc/.git shallow2 &&
  34        git --git-dir=shallow2/.git log --format=%s >actual &&
  35        cat <<EOF >expect &&
  36c
  37b
  38EOF
  39        test_cmp expect actual
  40'
  41
  42test_expect_success 'push from shallow clone' '
  43        (
  44        cd shallow &&
  45        commit 5 &&
  46        git push ../.git +master:refs/remotes/shallow/master
  47        ) &&
  48        git log --format=%s shallow/master >actual &&
  49        git fsck &&
  50        cat <<EOF >expect &&
  515
  524
  533
  542
  551
  56EOF
  57        test_cmp expect actual
  58'
  59
  60test_expect_success 'push from shallow clone, with grafted roots' '
  61        (
  62        cd shallow2 &&
  63        test_must_fail git push ../.git +master:refs/remotes/shallow2/master 2>err &&
  64        grep "shallow2/master.*shallow update not allowed" err
  65        ) &&
  66        test_must_fail git rev-parse shallow2/master &&
  67        git fsck
  68'
  69
  70test_expect_success 'add new shallow root with receive.updateshallow on' '
  71        test_config receive.shallowupdate true &&
  72        (
  73        cd shallow2 &&
  74        git push ../.git +master:refs/remotes/shallow2/master
  75        ) &&
  76        git log --format=%s shallow2/master >actual &&
  77        git fsck &&
  78        cat <<EOF >expect &&
  79c
  80b
  81EOF
  82        test_cmp expect actual
  83'
  84
  85test_expect_success 'push from shallow to shallow' '
  86        (
  87        cd shallow &&
  88        git --git-dir=../shallow2/.git config receive.shallowupdate true &&
  89        git push ../shallow2/.git +master:refs/remotes/shallow/master &&
  90        git --git-dir=../shallow2/.git config receive.shallowupdate false
  91        ) &&
  92        (
  93        cd shallow2 &&
  94        git log --format=%s shallow/master >actual &&
  95        git fsck &&
  96        cat <<EOF >expect &&
  975
  984
  993
 100EOF
 101        test_cmp expect actual
 102        )
 103'
 104
 105test_expect_success 'push from full to shallow' '
 106        ! git --git-dir=shallow2/.git cat-file blob `echo 1|git hash-object --stdin` &&
 107        commit 1 &&
 108        git push shallow2/.git +master:refs/remotes/top/master &&
 109        (
 110        cd shallow2 &&
 111        git log --format=%s top/master >actual &&
 112        git fsck &&
 113        cat <<EOF >expect &&
 1141
 1154
 1163
 117EOF
 118        test_cmp expect actual &&
 119        git cat-file blob `echo 1|git hash-object --stdin` >/dev/null
 120        )
 121'
 122
 123test_done