1#!/bin/sh
   2test_description='test git wire-protocol transition'
   4TEST_NO_CREATE_REPO=1
   6. ./test-lib.sh
   8# Test protocol v1 with 'git://' transport
  10#
  11. "$TEST_DIRECTORY"/lib-git-daemon.sh
  12start_git_daemon --export-all --enable=receive-pack
  13daemon_parent=$GIT_DAEMON_DOCUMENT_ROOT_PATH/parent
  14test_expect_success 'create repo to be served by git-daemon' '
  16        git init "$daemon_parent" &&
  17        test_commit -C "$daemon_parent" one
  18'
  19test_expect_success 'clone with git:// using protocol v1' '
  21        GIT_TRACE_PACKET=1 git -c protocol.version=1 \
  22                clone "$GIT_DAEMON_URL/parent" daemon_child 2>log &&
  23        git -C daemon_child log -1 --format=%s >actual &&
  25        git -C "$daemon_parent" log -1 --format=%s >expect &&
  26        test_cmp expect actual &&
  27        # Client requested to use protocol v1
  29        grep "clone> .*\\\0\\\0version=1\\\0$" log &&
  30        # Server responded using protocol v1
  31        grep "clone< version 1" log
  32'
  33test_expect_success 'fetch with git:// using protocol v1' '
  35        test_commit -C "$daemon_parent" two &&
  36        GIT_TRACE_PACKET=1 git -C daemon_child -c protocol.version=1 \
  38                fetch 2>log &&
  39        git -C daemon_child log -1 --format=%s origin/master >actual &&
  41        git -C "$daemon_parent" log -1 --format=%s >expect &&
  42        test_cmp expect actual &&
  43        # Client requested to use protocol v1
  45        grep "fetch> .*\\\0\\\0version=1\\\0$" log &&
  46        # Server responded using protocol v1
  47        grep "fetch< version 1" log
  48'
  49test_expect_success 'pull with git:// using protocol v1' '
  51        GIT_TRACE_PACKET=1 git -C daemon_child -c protocol.version=1 \
  52                pull 2>log &&
  53        git -C daemon_child log -1 --format=%s >actual &&
  55        git -C "$daemon_parent" log -1 --format=%s >expect &&
  56        test_cmp expect actual &&
  57        # Client requested to use protocol v1
  59        grep "fetch> .*\\\0\\\0version=1\\\0$" log &&
  60        # Server responded using protocol v1
  61        grep "fetch< version 1" log
  62'
  63test_expect_success 'push with git:// using protocol v1' '
  65        test_commit -C daemon_child three &&
  66        # Push to another branch, as the target repository has the
  68        # master branch checked out and we cannot push into it.
  69        GIT_TRACE_PACKET=1 git -C daemon_child -c protocol.version=1 \
  70                push origin HEAD:client_branch 2>log &&
  71        git -C daemon_child log -1 --format=%s >actual &&
  73        git -C "$daemon_parent" log -1 --format=%s client_branch >expect &&
  74        test_cmp expect actual &&
  75        # Client requested to use protocol v1
  77        grep "push> .*\\\0\\\0version=1\\\0$" log &&
  78        # Server responded using protocol v1
  79        grep "push< version 1" log
  80'
  81stop_git_daemon
  83# Test protocol v1 with 'file://' transport
  85#
  86test_expect_success 'create repo to be served by file:// transport' '
  87        git init file_parent &&
  88        test_commit -C file_parent one
  89'
  90test_expect_success 'clone with file:// using protocol v1' '
  92        GIT_TRACE_PACKET=1 git -c protocol.version=1 \
  93                clone "file://$(pwd)/file_parent" file_child 2>log &&
  94        git -C file_child log -1 --format=%s >actual &&
  96        git -C file_parent log -1 --format=%s >expect &&
  97        test_cmp expect actual &&
  98        # Server responded using protocol v1
 100        grep "clone< version 1" log
 101'
 102test_expect_success 'fetch with file:// using protocol v1' '
 104        test_commit -C file_parent two &&
 105        GIT_TRACE_PACKET=1 git -C file_child -c protocol.version=1 \
 107                fetch 2>log &&
 108        git -C file_child log -1 --format=%s origin/master >actual &&
 110        git -C file_parent log -1 --format=%s >expect &&
 111        test_cmp expect actual &&
 112        # Server responded using protocol v1
 114        grep "fetch< version 1" log
 115'
 116test_expect_success 'pull with file:// using protocol v1' '
 118        GIT_TRACE_PACKET=1 git -C file_child -c protocol.version=1 \
 119                pull 2>log &&
 120        git -C file_child log -1 --format=%s >actual &&
 122        git -C file_parent log -1 --format=%s >expect &&
 123        test_cmp expect actual &&
 124        # Server responded using protocol v1
 126        grep "fetch< version 1" log
 127'
 128test_expect_success 'push with file:// using protocol v1' '
 130        test_commit -C file_child three &&
 131        # Push to another branch, as the target repository has the
 133        # master branch checked out and we cannot push into it.
 134        GIT_TRACE_PACKET=1 git -C file_child -c protocol.version=1 \
 135                push origin HEAD:client_branch 2>log &&
 136        git -C file_child log -1 --format=%s >actual &&
 138        git -C file_parent log -1 --format=%s client_branch >expect &&
 139        test_cmp expect actual &&
 140        # Server responded using protocol v1
 142        grep "push< version 1" log
 143'
 144# Test protocol v1 with 'ssh://' transport
 146#
 147test_expect_success 'setup ssh wrapper' '
 148        GIT_SSH="$GIT_BUILD_DIR/t/helper/test-fake-ssh" &&
 149        export GIT_SSH &&
 150        GIT_SSH_VARIANT=ssh &&
 151        export GIT_SSH_VARIANT &&
 152        export TRASH_DIRECTORY &&
 153        >"$TRASH_DIRECTORY"/ssh-output
 154'
 155expect_ssh () {
 157        test_when_finished '(cd "$TRASH_DIRECTORY" && rm -f ssh-expect && >ssh-output)' &&
 158        echo "ssh: -o SendEnv=GIT_PROTOCOL myhost $1 '$PWD/ssh_parent'" >"$TRASH_DIRECTORY/ssh-expect" &&
 159        (cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output)
 160}
 161test_expect_success 'create repo to be served by ssh:// transport' '
 163        git init ssh_parent &&
 164        test_commit -C ssh_parent one
 165'
 166test_expect_success 'clone with ssh:// using protocol v1' '
 168        GIT_TRACE_PACKET=1 git -c protocol.version=1 \
 169                clone "ssh://myhost:$(pwd)/ssh_parent" ssh_child 2>log &&
 170        expect_ssh git-upload-pack &&
 171        git -C ssh_child log -1 --format=%s >actual &&
 173        git -C ssh_parent log -1 --format=%s >expect &&
 174        test_cmp expect actual &&
 175        # Server responded using protocol v1
 177        grep "clone< version 1" log
 178'
 179test_expect_success 'fetch with ssh:// using protocol v1' '
 181        test_commit -C ssh_parent two &&
 182        GIT_TRACE_PACKET=1 git -C ssh_child -c protocol.version=1 \
 184                fetch 2>log &&
 185        expect_ssh git-upload-pack &&
 186        git -C ssh_child log -1 --format=%s origin/master >actual &&
 188        git -C ssh_parent log -1 --format=%s >expect &&
 189        test_cmp expect actual &&
 190        # Server responded using protocol v1
 192        grep "fetch< version 1" log
 193'
 194test_expect_success 'pull with ssh:// using protocol v1' '
 196        GIT_TRACE_PACKET=1 git -C ssh_child -c protocol.version=1 \
 197                pull 2>log &&
 198        expect_ssh git-upload-pack &&
 199        git -C ssh_child log -1 --format=%s >actual &&
 201        git -C ssh_parent log -1 --format=%s >expect &&
 202        test_cmp expect actual &&
 203        # Server responded using protocol v1
 205        grep "fetch< version 1" log
 206'
 207test_expect_success 'push with ssh:// using protocol v1' '
 209        test_commit -C ssh_child three &&
 210        # Push to another branch, as the target repository has the
 212        # master branch checked out and we cannot push into it.
 213        GIT_TRACE_PACKET=1 git -C ssh_child -c protocol.version=1 \
 214                push origin HEAD:client_branch 2>log &&
 215        expect_ssh git-receive-pack &&
 216        git -C ssh_child log -1 --format=%s >actual &&
 218        git -C ssh_parent log -1 --format=%s client_branch >expect &&
 219        test_cmp expect actual &&
 220        # Server responded using protocol v1
 222        grep "push< version 1" log
 223'
 224# Test protocol v1 with 'http://' transport
 226#
 227. "$TEST_DIRECTORY"/lib-httpd.sh
 228start_httpd
 229test_expect_success 'create repo to be served by http:// transport' '
 231        git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
 232        git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" config http.receivepack true &&
 233        test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" one
 234'
 235test_expect_success 'clone with http:// using protocol v1' '
 237        GIT_TRACE_PACKET=1 GIT_TRACE_CURL=1 git -c protocol.version=1 \
 238                clone "$HTTPD_URL/smart/http_parent" http_child 2>log &&
 239        git -C http_child log -1 --format=%s >actual &&
 241        git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect &&
 242        test_cmp expect actual &&
 243        # Client requested to use protocol v1
 245        grep "Git-Protocol: version=1" log &&
 246        # Server responded using protocol v1
 247        grep "git< version 1" log
 248'
 249test_expect_success 'fetch with http:// using protocol v1' '
 251        test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two &&
 252        GIT_TRACE_PACKET=1 git -C http_child -c protocol.version=1 \
 254                fetch 2>log &&
 255        git -C http_child log -1 --format=%s origin/master >actual &&
 257        git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect &&
 258        test_cmp expect actual &&
 259        # Server responded using protocol v1
 261        grep "git< version 1" log
 262'
 263test_expect_success 'pull with http:// using protocol v1' '
 265        GIT_TRACE_PACKET=1 git -C http_child -c protocol.version=1 \
 266                pull 2>log &&
 267        git -C http_child log -1 --format=%s >actual &&
 269        git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect &&
 270        test_cmp expect actual &&
 271        # Server responded using protocol v1
 273        grep "git< version 1" log
 274'
 275test_expect_success 'push with http:// using protocol v1' '
 277        test_commit -C http_child three &&
 278        # Push to another branch, as the target repository has the
 280        # master branch checked out and we cannot push into it.
 281        GIT_TRACE_PACKET=1 git -C http_child -c protocol.version=1 \
 282                push origin HEAD:client_branch && #2>log &&
 283        git -C http_child log -1 --format=%s >actual &&
 285        git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s client_branch >expect &&
 286        test_cmp expect actual &&
 287        # Server responded using protocol v1
 289        grep "git< version 1" log
 290'
 291stop_httpd
 293test_done