1#!/bin/sh 2# Copyright (c) 2012 Felipe Contreras 3# 4# Slightly modified version of git-remote-testgit(1). Copied from the 5# git-2.27 source tree (t/t5801/git-remote-testgit). As it was copied 6# from Git itself, it is licensed under the GNU General Public License 7# version 2. Refer to the git-2.27 source tree for further license 8# information. 9#10# This file is intended to be installed to $PATH on your git server.1112if [ $# -ne 1 ]; then13 echo "USAGE: ${0##*/} GIT_REPOSITORY" 1>&214 exit 115fi1617GIT_DIR="${1}/$(git -C "${1}" rev-parse --git-dir)"18export GIT_DIR1920if [ ! -d "${GIT_DIR}" ]; then21 echo "Repository '${GIT_DIR}' does not exist" 1>&222 exit 123fi2425dir="$GIT_DIR/secure"26mkdir -p "$dir"2728h_refspec="refs/heads/*:refs/testgit/heads/*"29t_refspec="refs/tags/*:refs/testgit/tags/*"3031while read line32do33 case $line in34 capabilities)35 echo 'import'36 echo 'export'37 test -n "$h_refspec" && echo "refspec $h_refspec"38 test -n "$t_refspec" && echo "refspec $t_refspec"39 echo40 ;;41 list)42 git for-each-ref --format='? %(refname)' 'refs/heads/' 'refs/tags/'43 head=$(git symbolic-ref HEAD)44 echo "@$head HEAD"45 echo46 ;;47 import*)48 # read all import lines49 while true50 do51 ref="${line#* }"52 refs="$refs $ref"53 read line54 test "${line%% *}" != "import" && break55 done5657 echo "feature done"58 git fast-export \59 --refspec="$h_refspec" \60 --refspec="$t_refspec" \61 $refs62 echo "done"63 ;;64 export)65 before=$(git for-each-ref --format=' %(refname) %(objectname) ')6667 # As file contents are encrypted, files on the git68 # server have a different checksum than local files,69 # i.e. the entire commit history is different. For this70 # reason force pushing is required and likely unavoidable.71 git fast-import \72 --force \73 --quiet7475 # figure out which refs were updated76 git for-each-ref --format='%(refname) %(objectname)' |77 while read ref a78 do79 case "$before" in80 *" $ref $a "*)81 continue ;; # unchanged82 esac8384 echo "ok $ref"85 done8687 echo88 ;;89 '')90 exit91 ;;92 esac93done