git-remote-testgit.shon commit t4116-apply-reverse.sh: use the $( ... ) construct for command substitution (991a9c3)
   1#!/bin/sh
   2# Copyright (c) 2012 Felipe Contreras
   3
   4alias=$1
   5url=$2
   6
   7dir="$GIT_DIR/testgit/$alias"
   8prefix="refs/testgit/$alias"
   9
  10default_refspec="refs/heads/*:${prefix}/heads/*"
  11
  12refspec="${GIT_REMOTE_TESTGIT_REFSPEC-$default_refspec}"
  13
  14test -z "$refspec" && prefix="refs"
  15
  16export GIT_DIR="$url/.git"
  17
  18force=
  19
  20mkdir -p "$dir"
  21
  22if test -z "$GIT_REMOTE_TESTGIT_NO_MARKS"
  23then
  24        gitmarks="$dir/git.marks"
  25        testgitmarks="$dir/testgit.marks"
  26        test -e "$gitmarks" || >"$gitmarks"
  27        test -e "$testgitmarks" || >"$testgitmarks"
  28fi
  29
  30while read line
  31do
  32        case $line in
  33        capabilities)
  34                echo 'import'
  35                echo 'export'
  36                test -n "$refspec" && echo "refspec $refspec"
  37                if test -n "$gitmarks"
  38                then
  39                        echo "*import-marks $gitmarks"
  40                        echo "*export-marks $gitmarks"
  41                fi
  42                test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
  43                test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update"
  44                echo 'option'
  45                echo
  46                ;;
  47        list)
  48                git for-each-ref --format='? %(refname)' 'refs/heads/'
  49                head=$(git symbolic-ref HEAD)
  50                echo "@$head HEAD"
  51                echo
  52                ;;
  53        import*)
  54                # read all import lines
  55                while true
  56                do
  57                        ref="${line#* }"
  58                        refs="$refs $ref"
  59                        read line
  60                        test "${line%% *}" != "import" && break
  61                done
  62
  63                if test -n "$gitmarks"
  64                then
  65                        echo "feature import-marks=$gitmarks"
  66                        echo "feature export-marks=$gitmarks"
  67                fi
  68
  69                if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
  70                then
  71                        echo "feature done"
  72                        exit 1
  73                fi
  74
  75                echo "feature done"
  76                git fast-export \
  77                        ${testgitmarks:+"--import-marks=$testgitmarks"} \
  78                        ${testgitmarks:+"--export-marks=$testgitmarks"} \
  79                        $refs |
  80                sed -e "s#refs/heads/#${prefix}/heads/#g"
  81                echo "done"
  82                ;;
  83        export)
  84                if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
  85                then
  86                        # consume input so fast-export doesn't get SIGPIPE;
  87                        # git would also notice that case, but we want
  88                        # to make sure we are exercising the later
  89                        # error checks
  90                        while read line; do
  91                                test "done" = "$line" && break
  92                        done
  93                        exit 1
  94                fi
  95
  96                before=$(git for-each-ref --format=' %(refname) %(objectname) ')
  97
  98                git fast-import \
  99                        ${force:+--force} \
 100                        ${testgitmarks:+"--import-marks=$testgitmarks"} \
 101                        ${testgitmarks:+"--export-marks=$testgitmarks"} \
 102                        --quiet
 103
 104                # figure out which refs were updated
 105                git for-each-ref --format='%(refname) %(objectname)' |
 106                while read ref a
 107                do
 108                        case "$before" in
 109                        *" $ref $a "*)
 110                                continue ;;     # unchanged
 111                        esac
 112                        if test -z "$GIT_REMOTE_TESTGIT_PUSH_ERROR"
 113                        then
 114                                echo "ok $ref"
 115                        else
 116                                echo "error $ref $GIT_REMOTE_TESTGIT_PUSH_ERROR"
 117                        fi
 118                done
 119
 120                echo
 121                ;;
 122        option\ *)
 123                read cmd opt val <<-EOF
 124                $line
 125                EOF
 126                case $opt in
 127                force)
 128                        test $val = "true" && force="true" || force=
 129                        echo "ok"
 130                        ;;
 131                *)
 132                        echo "unsupported"
 133                        ;;
 134                esac
 135                ;;
 136        '')
 137                exit
 138                ;;
 139        esac
 140done