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