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