t / t5701-git-serve.shon commit Merge branch 'sg/t5310-jgit-bitmap-test' (c4e7220)
   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        0000
  14        EOF
  15
  16        git serve --advertise-capabilities >out &&
  17        test-pkt-line unpack <out >actual &&
  18        test_cmp actual expect
  19'
  20
  21test_expect_success 'stateless-rpc flag does not list capabilities' '
  22        # Empty request
  23        test-pkt-line pack >in <<-EOF &&
  24        0000
  25        EOF
  26        git serve --stateless-rpc >out <in &&
  27        test_must_be_empty out &&
  28
  29        # EOF
  30        git serve --stateless-rpc >out &&
  31        test_must_be_empty out
  32'
  33
  34test_expect_success 'request invalid capability' '
  35        test-pkt-line pack >in <<-EOF &&
  36        foobar
  37        0000
  38        EOF
  39        test_must_fail git serve --stateless-rpc 2>err <in &&
  40        test_i18ngrep "unknown capability" err
  41'
  42
  43test_expect_success 'request with no command' '
  44        test-pkt-line pack >in <<-EOF &&
  45        agent=git/test
  46        0000
  47        EOF
  48        test_must_fail git serve --stateless-rpc 2>err <in &&
  49        test_i18ngrep "no command requested" err
  50'
  51
  52test_expect_success 'request invalid command' '
  53        test-pkt-line pack >in <<-EOF &&
  54        command=foo
  55        agent=git/test
  56        0000
  57        EOF
  58        test_must_fail git serve --stateless-rpc 2>err <in &&
  59        test_i18ngrep "invalid command" err
  60'
  61
  62# Test the basics of ls-refs
  63#
  64test_expect_success 'setup some refs and tags' '
  65        test_commit one &&
  66        git branch dev master &&
  67        test_commit two &&
  68        git symbolic-ref refs/heads/release refs/heads/master &&
  69        git tag -a -m "annotated tag" annotated-tag
  70'
  71
  72test_expect_success 'basics of ls-refs' '
  73        test-pkt-line pack >in <<-EOF &&
  74        command=ls-refs
  75        0000
  76        EOF
  77
  78        cat >expect <<-EOF &&
  79        $(git rev-parse HEAD) HEAD
  80        $(git rev-parse refs/heads/dev) refs/heads/dev
  81        $(git rev-parse refs/heads/master) refs/heads/master
  82        $(git rev-parse refs/heads/release) refs/heads/release
  83        $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag
  84        $(git rev-parse refs/tags/one) refs/tags/one
  85        $(git rev-parse refs/tags/two) refs/tags/two
  86        0000
  87        EOF
  88
  89        git serve --stateless-rpc <in >out &&
  90        test-pkt-line unpack <out >actual &&
  91        test_cmp actual expect
  92'
  93
  94test_expect_success 'basic ref-prefixes' '
  95        test-pkt-line pack >in <<-EOF &&
  96        command=ls-refs
  97        0001
  98        ref-prefix refs/heads/master
  99        ref-prefix refs/tags/one
 100        0000
 101        EOF
 102
 103        cat >expect <<-EOF &&
 104        $(git rev-parse refs/heads/master) refs/heads/master
 105        $(git rev-parse refs/tags/one) refs/tags/one
 106        0000
 107        EOF
 108
 109        git serve --stateless-rpc <in >out &&
 110        test-pkt-line unpack <out >actual &&
 111        test_cmp actual expect
 112'
 113
 114test_expect_success 'refs/heads prefix' '
 115        test-pkt-line pack >in <<-EOF &&
 116        command=ls-refs
 117        0001
 118        ref-prefix refs/heads/
 119        0000
 120        EOF
 121
 122        cat >expect <<-EOF &&
 123        $(git rev-parse refs/heads/dev) refs/heads/dev
 124        $(git rev-parse refs/heads/master) refs/heads/master
 125        $(git rev-parse refs/heads/release) refs/heads/release
 126        0000
 127        EOF
 128
 129        git serve --stateless-rpc <in >out &&
 130        test-pkt-line unpack <out >actual &&
 131        test_cmp actual expect
 132'
 133
 134test_expect_success 'peel parameter' '
 135        test-pkt-line pack >in <<-EOF &&
 136        command=ls-refs
 137        0001
 138        peel
 139        ref-prefix refs/tags/
 140        0000
 141        EOF
 142
 143        cat >expect <<-EOF &&
 144        $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag peeled:$(git rev-parse refs/tags/annotated-tag^{})
 145        $(git rev-parse refs/tags/one) refs/tags/one
 146        $(git rev-parse refs/tags/two) refs/tags/two
 147        0000
 148        EOF
 149
 150        git serve --stateless-rpc <in >out &&
 151        test-pkt-line unpack <out >actual &&
 152        test_cmp actual expect
 153'
 154
 155test_expect_success 'symrefs parameter' '
 156        test-pkt-line pack >in <<-EOF &&
 157        command=ls-refs
 158        0001
 159        symrefs
 160        ref-prefix refs/heads/
 161        0000
 162        EOF
 163
 164        cat >expect <<-EOF &&
 165        $(git rev-parse refs/heads/dev) refs/heads/dev
 166        $(git rev-parse refs/heads/master) refs/heads/master
 167        $(git rev-parse refs/heads/release) refs/heads/release symref-target:refs/heads/master
 168        0000
 169        EOF
 170
 171        git serve --stateless-rpc <in >out &&
 172        test-pkt-line unpack <out >actual &&
 173        test_cmp actual expect
 174'
 175
 176test_done