t / t5537-fetch-shallow.shon commit Merge branch 'bw/rebase-autostash-keep-current-branch' (974bdb0)
   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 --unshallow from shallow clone' '
  83        (
  84        cd shallow2 &&
  85        git fetch --unshallow &&
  86        git fsck &&
  87        git log --format=%s origin/master >actual &&
  88        cat <<EOF >expect &&
  896
  905
  914
  923
  93EOF
  94        test_cmp expect actual
  95        )
  96'
  97
  98test_expect_success 'fetch something upstream has but hidden by clients shallow boundaries' '
  99        # the blob "1" is available in .git but hidden by the
 100        # shallow2/.git/shallow and it should be resent
 101        ! git --git-dir=shallow2/.git cat-file blob $(echo 1|git hash-object --stdin) >/dev/null &&
 102        echo 1 >1.t &&
 103        git add 1.t &&
 104        git commit -m add-1-back &&
 105        (
 106        cd shallow2 &&
 107        git fetch ../.git +refs/heads/master:refs/remotes/top/master &&
 108        git fsck &&
 109        git log --format=%s top/master >actual &&
 110        cat <<EOF >expect &&
 111add-1-back
 1124
 1133
 114EOF
 115        test_cmp expect actual
 116        ) &&
 117        git --git-dir=shallow2/.git cat-file blob $(echo 1|git hash-object --stdin) >/dev/null
 118
 119'
 120
 121test_expect_success 'fetch that requires changes in .git/shallow is filtered' '
 122        (
 123        cd shallow &&
 124        git checkout --orphan no-shallow &&
 125        commit no-shallow
 126        ) &&
 127        git init notshallow &&
 128        (
 129        cd notshallow &&
 130        git fetch ../shallow/.git refs/heads/*:refs/remotes/shallow/*&&
 131        git for-each-ref --format="%(refname)" >actual.refs &&
 132        cat <<EOF >expect.refs &&
 133refs/remotes/shallow/no-shallow
 134EOF
 135        test_cmp expect.refs actual.refs &&
 136        git log --format=%s shallow/no-shallow >actual &&
 137        cat <<EOF >expect &&
 138no-shallow
 139EOF
 140        test_cmp expect actual
 141        )
 142'
 143
 144test_expect_success 'fetch --update-shallow' '
 145        (
 146        cd shallow &&
 147        git checkout master &&
 148        commit 7 &&
 149        git tag -m foo heavy-tag HEAD^ &&
 150        git tag light-tag HEAD^:tracked
 151        ) &&
 152        (
 153        cd notshallow &&
 154        git fetch --update-shallow ../shallow/.git refs/heads/*:refs/remotes/shallow/* &&
 155        git fsck &&
 156        git for-each-ref --sort=refname --format="%(refname)" >actual.refs &&
 157        cat <<EOF >expect.refs &&
 158refs/remotes/shallow/master
 159refs/remotes/shallow/no-shallow
 160refs/tags/heavy-tag
 161refs/tags/light-tag
 162EOF
 163        test_cmp expect.refs actual.refs &&
 164        git log --format=%s shallow/master >actual &&
 165        cat <<EOF >expect &&
 1667
 1676
 1685
 1694
 1703
 171EOF
 172        test_cmp expect actual
 173        )
 174'
 175
 176test_expect_success POSIXPERM,SANITY 'shallow fetch from a read-only repo' '
 177        cp -R .git read-only.git &&
 178        test_when_finished "find read-only.git -type d -print | xargs chmod +w" &&
 179        find read-only.git -print | xargs chmod -w &&
 180        git clone --no-local --depth=2 read-only.git from-read-only &&
 181        git --git-dir=from-read-only/.git log --format=%s >actual &&
 182        cat >expect <<EOF &&
 183add-1-back
 1844
 185EOF
 186        test_cmp expect actual
 187'
 188
 189test_expect_success '.git/shallow is edited by repack' '
 190        git init shallow-server &&
 191        test_commit -C shallow-server A &&
 192        test_commit -C shallow-server B &&
 193        git -C shallow-server checkout -b branch &&
 194        test_commit -C shallow-server C &&
 195        test_commit -C shallow-server E &&
 196        test_commit -C shallow-server D &&
 197        d="$(git -C shallow-server rev-parse --verify D^0)" &&
 198        git -C shallow-server checkout master &&
 199
 200        git clone --depth=1 --no-tags --no-single-branch \
 201                "file://$PWD/shallow-server" shallow-client &&
 202
 203        : now remove the branch and fetch with prune &&
 204        git -C shallow-server branch -D branch &&
 205        git -C shallow-client fetch --prune --depth=1 \
 206                origin "+refs/heads/*:refs/remotes/origin/*" &&
 207        git -C shallow-client repack -adfl &&
 208        test_must_fail git -C shallow-client rev-parse --verify $d^0 &&
 209        ! grep $d shallow-client/.git/shallow &&
 210
 211        git -C shallow-server branch branch-orig $d &&
 212        git -C shallow-client fetch --prune --depth=2 \
 213                origin "+refs/heads/*:refs/remotes/origin/*"
 214'
 215
 216. "$TEST_DIRECTORY"/lib-httpd.sh
 217start_httpd
 218
 219REPO="$HTTPD_DOCUMENT_ROOT_PATH/repo"
 220
 221test_expect_success 'shallow fetches check connectivity before writing shallow file' '
 222        rm -rf "$REPO" client &&
 223
 224        git init "$REPO" &&
 225        test_commit -C "$REPO" one &&
 226        test_commit -C "$REPO" two &&
 227        test_commit -C "$REPO" three &&
 228
 229        git init client &&
 230
 231        # Use protocol v2 to ensure that shallow information is sent exactly
 232        # once by the server, since we are planning to manipulate it.
 233        git -C "$REPO" config protocol.version 2 &&
 234        git -C client config protocol.version 2 &&
 235
 236        git -C client fetch --depth=2 "$HTTPD_URL/one_time_sed/repo" master:a_branch &&
 237
 238        # Craft a situation in which the server sends back an unshallow request
 239        # with an empty packfile. This is done by refetching with a shorter
 240        # depth (to ensure that the packfile is empty), and overwriting the
 241        # shallow line in the response with the unshallow line we want.
 242        printf "s/0034shallow %s/0036unshallow %s/" \
 243               "$(git -C "$REPO" rev-parse HEAD)" \
 244               "$(git -C "$REPO" rev-parse HEAD^)" \
 245               >"$HTTPD_ROOT_PATH/one-time-sed" &&
 246        test_must_fail env GIT_TEST_SIDEBAND_ALL=0 git -C client \
 247                fetch --depth=1 "$HTTPD_URL/one_time_sed/repo" \
 248                master:a_branch &&
 249
 250        # Ensure that the one-time-sed script was used.
 251        ! test -e "$HTTPD_ROOT_PATH/one-time-sed" &&
 252
 253        # Ensure that the resulting repo is consistent, despite our failure to
 254        # fetch.
 255        git -C client fsck
 256'
 257
 258# DO NOT add non-httpd-specific tests here, because the last part of this
 259# test script is only executed when httpd is available and enabled.
 260
 261test_done