t / t5408-send-pack-stdin.shon commit Merge branch 'ss/clone-guess-dir-name-simplify' (721f5bb)
   1#!/bin/sh
   2
   3test_description='send-pack --stdin tests'
   4. ./test-lib.sh
   5
   6create_ref () {
   7        tree=$(git write-tree) &&
   8        test_tick &&
   9        commit=$(echo "$1" | git commit-tree $tree) &&
  10        git update-ref "$1" $commit
  11}
  12
  13clear_remote () {
  14        rm -rf remote.git &&
  15        git init --bare remote.git
  16}
  17
  18verify_push () {
  19        git rev-parse "$1" >expect &&
  20        git --git-dir=remote.git rev-parse "${2:-$1}" >actual &&
  21        test_cmp expect actual
  22}
  23
  24test_expect_success 'setup refs' '
  25        cat >refs <<-\EOF &&
  26        refs/heads/A
  27        refs/heads/C
  28        refs/tags/D
  29        refs/heads/B
  30        refs/tags/E
  31        EOF
  32        for i in $(cat refs); do
  33                create_ref $i || return 1
  34        done
  35'
  36
  37# sanity check our setup
  38test_expect_success 'refs on cmdline' '
  39        clear_remote &&
  40        git send-pack remote.git $(cat refs) &&
  41        for i in $(cat refs); do
  42                verify_push $i || return 1
  43        done
  44'
  45
  46test_expect_success 'refs over stdin' '
  47        clear_remote &&
  48        git send-pack remote.git --stdin <refs &&
  49        for i in $(cat refs); do
  50                verify_push $i || return 1
  51        done
  52'
  53
  54test_expect_success 'stdin lines are full refspecs' '
  55        clear_remote &&
  56        echo "A:other" >input &&
  57        git send-pack remote.git --stdin <input &&
  58        verify_push refs/heads/A refs/heads/other
  59'
  60
  61test_expect_success 'stdin mixed with cmdline' '
  62        clear_remote &&
  63        echo A >input &&
  64        git send-pack remote.git --stdin B <input &&
  65        verify_push A &&
  66        verify_push B
  67'
  68
  69test_expect_success 'cmdline refs written in order' '
  70        clear_remote &&
  71        test_must_fail git send-pack remote.git A:foo B:foo &&
  72        verify_push A foo
  73'
  74
  75test_expect_success '--stdin refs come after cmdline' '
  76        clear_remote &&
  77        echo A:foo >input &&
  78        test_must_fail git send-pack remote.git --stdin B:foo <input &&
  79        verify_push B foo
  80'
  81
  82test_expect_success 'refspecs and --mirror do not mix (cmdline)' '
  83        clear_remote &&
  84        test_must_fail git send-pack remote.git --mirror $(cat refs)
  85'
  86
  87test_expect_success 'refspecs and --mirror do not mix (stdin)' '
  88        clear_remote &&
  89        test_must_fail git send-pack remote.git --mirror --stdin <refs
  90'
  91
  92test_done