1#!/bin/sh2# Copyright (c) 2012 Felipe Contreras34# The first argument can be a url when the fetch/push command was a url5# instead of a configured remote. In this case, use a generic alias.6if test "$1" = "testgit::$2"; then7alias=_8else9alias=$110fi11url=$21213dir="$GIT_DIR/testgit/$alias"1415refspec="refs/heads/*:refs/testgit/$alias/heads/*"1617test -n "$GIT_REMOTE_TESTGIT_NOREFSPEC" && refspec=""1819GIT_DIR="$url/.git"20export GIT_DIR2122force=2324mkdir -p "$dir"2526if test -z "$GIT_REMOTE_TESTGIT_NO_MARKS"27then28gitmarks="$dir/git.marks"29testgitmarks="$dir/testgit.marks"30test -e "$gitmarks" || >"$gitmarks"31test -e "$testgitmarks" || >"$testgitmarks"32fi3334while read line35do36case $line in37capabilities)38echo 'import'39echo 'export'40test -n "$refspec" && echo "refspec $refspec"41if test -n "$gitmarks"42then43echo "*import-marks $gitmarks"44echo "*export-marks $gitmarks"45fi46test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"47test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update"48echo 'option'49echo50;;51list)52git for-each-ref --format='? %(refname)' 'refs/heads/'53head=$(git symbolic-ref HEAD)54echo "@$head HEAD"55echo56;;57import*)58# read all import lines59while true60do61ref="${line#* }"62refs="$refs $ref"63read line64test "${line%% *}" != "import" && break65done6667if test -n "$gitmarks"68then69echo "feature import-marks=$gitmarks"70echo "feature export-marks=$gitmarks"71fi7273if test -n "$GIT_REMOTE_TESTGIT_FAILURE"74then75echo "feature done"76exit 177fi7879echo "feature done"80git fast-export \81${refspec:+"--refspec=$refspec"} \82${testgitmarks:+"--import-marks=$testgitmarks"} \83${testgitmarks:+"--export-marks=$testgitmarks"} \84$refs85echo "done"86;;87export)88if test -n "$GIT_REMOTE_TESTGIT_FAILURE"89then90# consume input so fast-export doesn't get SIGPIPE;91# git would also notice that case, but we want92# to make sure we are exercising the later93# error checks94while read line; do95test "done" = "$line" && break96done97exit 198fi99100before=$(git for-each-ref --format=' %(refname) %(objectname) ')101102git fast-import \103${force:+--force} \104${testgitmarks:+"--import-marks=$testgitmarks"} \105${testgitmarks:+"--export-marks=$testgitmarks"} \106--quiet107108# figure out which refs were updated109git for-each-ref --format='%(refname) %(objectname)' |110while read ref a111do112case "$before" in113*" $ref $a "*)114continue ;; # unchanged115esac116if test -z "$GIT_REMOTE_TESTGIT_PUSH_ERROR"117then118echo "ok $ref"119else120echo "error $ref $GIT_REMOTE_TESTGIT_PUSH_ERROR"121fi122done123124echo125;;126option\ *)127read cmd opt val <<-EOF128$line129EOF130case $opt in131force)132test $val = "true" && force="true" || force=133echo "ok"134;;135*)136echo "unsupported"137;;138esac139;;140'')141exit142;;143esac144done