#!/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" { setvar alias = '_' } else { setvar alias = "$1" } setvar url = "$2" setvar dir = ""$GIT_DIR/testgit/$alias"" setvar prefix = ""refs/testgit/$alias"" setvar default_refspec = ""refs/heads/*:${prefix}/heads/*"" setvar refspec = "${GIT_REMOTE_TESTGIT_REFSPEC-$default_refspec}" test -z $refspec && setvar prefix = ""refs"" setvar GIT_DIR = ""$url/.git"" export GIT_DIR setvar force = '' mkdir -p $dir if test -z $GIT_REMOTE_TESTGIT_NO_MARKS { setvar gitmarks = ""$dir/git.marks"" setvar testgitmarks = ""$dir/testgit.marks"" test -e $gitmarks || >"$gitmarks" test -e $testgitmarks || >"$testgitmarks" } while read line { case (line) { 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 } list { git for-each-ref --format='? %(refname)' 'refs/heads/' setvar head = $(git symbolic-ref HEAD) echo "@$head HEAD" echo } import* { # read all import lines while true { setvar ref = "${line#* }" setvar 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" } 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 } setvar 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 { case (before) { *" $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 } option\ * { read cmd opt val <<< """ $line """ case (opt) { force { test $val = "true" && setvar force = ""true"" || setvar force = '' echo "ok" } * { echo "unsupported" } } } '' { exit } } }