#!/bin/sh # Copyright (c) 2012 Felipe Contreras # The first argument can be a url when the fetch/push command was a url # instead of a configured remote. In this case, use a generic alias. if test $1 = "testgit::$2" { setglobal alias = '_' } else { setglobal alias = $1 } setglobal url = $2 setglobal dir = ""$GIT_DIR/testgit/$alias"" setglobal prefix = ""refs/testgit/$alias"" setglobal default_refspec = ""refs/heads/*:$(prefix)/heads/*"" setglobal refspec = $(GIT_REMOTE_TESTGIT_REFSPEC-$default_refspec) test -z $refspec && setglobal prefix = '"refs'" setglobal GIT_DIR = ""$url/.git"" export GIT_DIR setglobal force = '' mkdir -p $dir if test -z $GIT_REMOTE_TESTGIT_NO_MARKS { setglobal gitmarks = ""$dir/git.marks"" setglobal testgitmarks = ""$dir/testgit.marks"" test -e $gitmarks || >$gitmarks test -e $testgitmarks || >$testgitmarks } while read line { match $line { with capabilities echo 'import' echo 'export' test -n $refspec && echo "refspec $refspec" if test -n $gitmarks { echo "*import-marks $gitmarks" echo "*export-marks $gitmarks" } test -n $GIT_REMOTE_TESTGIT_SIGNED_TAGS && echo "signed-tags" test -n $GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE && echo "no-private-update" echo 'option' echo with list git for-each-ref --format='? %(refname)' 'refs/heads/' setglobal head = $[git symbolic-ref HEAD] echo "@$head HEAD" echo with import* # read all import lines while true { setglobal ref = $(line#* ) setglobal refs = ""$refs $ref"" read line test $(line%% *) != "import" && break } if test -n $gitmarks { echo "feature import-marks=$gitmarks" echo "feature export-marks=$gitmarks" } if test -n $GIT_REMOTE_TESTGIT_FAILURE { echo "feature done" exit 1 } echo "feature done" git fast-export \ $(testgitmarks:+"--import-marks=$testgitmarks") \ $(testgitmarks:+"--export-marks=$testgitmarks") \ $refs | sed -e "s#refs/heads/#$(prefix)/heads/#g" echo "done" with export if test -n $GIT_REMOTE_TESTGIT_FAILURE { # consume input so fast-export doesn't get SIGPIPE; # git would also notice that case, but we want # to make sure we are exercising the later # error checks while read line { test "done" = $line && break } exit 1 } setglobal before = $[git for-each-ref --format=' %(refname) %(objectname) ] git fast-import \ $(force:+--force) \ $(testgitmarks:+"--import-marks=$testgitmarks") \ $(testgitmarks:+"--export-marks=$testgitmarks") \ --quiet # figure out which refs were updated git for-each-ref --format='%(refname) %(objectname)' | while read ref a { match $before { with *" $ref $a "* continue # unchanged } if test -z $GIT_REMOTE_TESTGIT_PUSH_ERROR { echo "ok $ref" } else { echo "error $ref $GIT_REMOTE_TESTGIT_PUSH_ERROR" } } echo with option\ * read cmd opt val << """ $line """ match $opt { with force test $val = "true" && setglobal force = '"true'" || setglobal force = '' echo "ok" with * echo "unsupported" } with '' exit } }