t / t5701-git-serve.shon commit Merge branch 'ps/stash-in-c' (e36adf7)
   1#!/bin/sh
   2
   3test_description='test git-serve and server commands'
   4
   5. ./test-lib.sh
   6
   7test_expect_success 'test capability advertisement' '
   8        cat >expect <<-EOF &&
   9        version 2
  10        agent=git/$(git version | cut -d" " -f3)
  11        ls-refs
  12        fetch=shallow
  13        server-option
  14        0000
  15        EOF
  16
  17        GIT_TEST_SIDEBAND_ALL=0 git serve --advertise-capabilities >out &&
  18        test-tool pkt-line unpack <out >actual &&
  19        test_cmp expect actual
  20'
  21
  22test_expect_success 'stateless-rpc flag does not list capabilities' '
  23        # Empty request
  24        test-tool pkt-line pack >in <<-EOF &&
  25        0000
  26        EOF
  27        git serve --stateless-rpc >out <in &&
  28        test_must_be_empty out &&
  29
  30        # EOF
  31        git serve --stateless-rpc >out &&
  32        test_must_be_empty out
  33'
  34
  35test_expect_success 'request invalid capability' '
  36        test-tool pkt-line pack >in <<-EOF &&
  37        foobar
  38        0000
  39        EOF
  40        test_must_fail git serve --stateless-rpc 2>err <in &&
  41        test_i18ngrep "unknown capability" err
  42'
  43
  44test_expect_success 'request with no command' '
  45        test-tool pkt-line pack >in <<-EOF &&
  46        agent=git/test
  47        0000
  48        EOF
  49        test_must_fail git serve --stateless-rpc 2>err <in &&
  50        test_i18ngrep "no command requested" err
  51'
  52
  53test_expect_success 'request invalid command' '
  54        test-tool pkt-line pack >in <<-EOF &&
  55        command=foo
  56        agent=git/test
  57        0000
  58        EOF
  59        test_must_fail git serve --stateless-rpc 2>err <in &&
  60        test_i18ngrep "invalid command" err
  61'
  62
  63# Test the basics of ls-refs
  64#
  65test_expect_success 'setup some refs and tags' '
  66        test_commit one &&
  67        git branch dev master &&
  68        test_commit two &&
  69        git symbolic-ref refs/heads/release refs/heads/master &&
  70        git tag -a -m "annotated tag" annotated-tag
  71'
  72
  73test_expect_success 'basics of ls-refs' '
  74        test-tool pkt-line pack >in <<-EOF &&
  75        command=ls-refs
  76        0000
  77        EOF
  78
  79        cat >expect <<-EOF &&
  80        $(git rev-parse HEAD) HEAD
  81        $(git rev-parse refs/heads/dev) refs/heads/dev
  82        $(git rev-parse refs/heads/master) refs/heads/master
  83        $(git rev-parse refs/heads/release) refs/heads/release
  84        $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag
  85        $(git rev-parse refs/tags/one) refs/tags/one
  86        $(git rev-parse refs/tags/two) refs/tags/two
  87        0000
  88        EOF
  89
  90        git serve --stateless-rpc <in >out &&
  91        test-tool pkt-line unpack <out >actual &&
  92        test_cmp expect actual
  93'
  94
  95test_expect_success 'basic ref-prefixes' '
  96        test-tool pkt-line pack >in <<-EOF &&
  97        command=ls-refs
  98        0001
  99        ref-prefix refs/heads/master
 100        ref-prefix refs/tags/one
 101        0000
 102        EOF
 103
 104        cat >expect <<-EOF &&
 105        $(git rev-parse refs/heads/master) refs/heads/master
 106        $(git rev-parse refs/tags/one) refs/tags/one
 107        0000
 108        EOF
 109
 110        git serve --stateless-rpc <in >out &&
 111        test-tool pkt-line unpack <out >actual &&
 112        test_cmp expect actual
 113'
 114
 115test_expect_success 'refs/heads prefix' '
 116        test-tool pkt-line pack >in <<-EOF &&
 117        command=ls-refs
 118        0001
 119        ref-prefix refs/heads/
 120        0000
 121        EOF
 122
 123        cat >expect <<-EOF &&
 124        $(git rev-parse refs/heads/dev) refs/heads/dev
 125        $(git rev-parse refs/heads/master) refs/heads/master
 126        $(git rev-parse refs/heads/release) refs/heads/release
 127        0000
 128        EOF
 129
 130        git serve --stateless-rpc <in >out &&
 131        test-tool pkt-line unpack <out >actual &&
 132        test_cmp expect actual
 133'
 134
 135test_expect_success 'peel parameter' '
 136        test-tool pkt-line pack >in <<-EOF &&
 137        command=ls-refs
 138        0001
 139        peel
 140        ref-prefix refs/tags/
 141        0000
 142        EOF
 143
 144        cat >expect <<-EOF &&
 145        $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag peeled:$(git rev-parse refs/tags/annotated-tag^{})
 146        $(git rev-parse refs/tags/one) refs/tags/one
 147        $(git rev-parse refs/tags/two) refs/tags/two
 148        0000
 149        EOF
 150
 151        git serve --stateless-rpc <in >out &&
 152        test-tool pkt-line unpack <out >actual &&
 153        test_cmp expect actual
 154'
 155
 156test_expect_success 'symrefs parameter' '
 157        test-tool pkt-line pack >in <<-EOF &&
 158        command=ls-refs
 159        0001
 160        symrefs
 161        ref-prefix refs/heads/
 162        0000
 163        EOF
 164
 165        cat >expect <<-EOF &&
 166        $(git rev-parse refs/heads/dev) refs/heads/dev
 167        $(git rev-parse refs/heads/master) refs/heads/master
 168        $(git rev-parse refs/heads/release) refs/heads/release symref-target:refs/heads/master
 169        0000
 170        EOF
 171
 172        git serve --stateless-rpc <in >out &&
 173        test-tool pkt-line unpack <out >actual &&
 174        test_cmp expect actual
 175'
 176
 177test_expect_success 'sending server-options' '
 178        test-tool pkt-line pack >in <<-EOF &&
 179        command=ls-refs
 180        server-option=hello
 181        server-option=world
 182        0001
 183        ref-prefix HEAD
 184        0000
 185        EOF
 186
 187        cat >expect <<-EOF &&
 188        $(git rev-parse HEAD) HEAD
 189        0000
 190        EOF
 191
 192        git serve --stateless-rpc <in >out &&
 193        test-tool pkt-line unpack <out >actual &&
 194        test_cmp expect actual
 195'
 196
 197test_expect_success 'unexpected lines are not allowed in fetch request' '
 198        git init server &&
 199
 200        test-tool pkt-line pack >in <<-EOF &&
 201        command=fetch
 202        0001
 203        this-is-not-a-command
 204        0000
 205        EOF
 206
 207        test_must_fail git -C server serve --stateless-rpc <in >/dev/null 2>err &&
 208        grep "unexpected line: .this-is-not-a-command." err
 209'
 210
 211test_done