1#!/bin/sh
2# Copyright (c) 2012 Felipe Contreras
3
4alias=$1
5url=$2
6
7dir="$GIT_DIR/testgit/$alias"
8prefix="refs/testgit/$alias"
9
10default_refspec="refs/heads/*:${prefix}/heads/*"
11
12refspec="${GIT_REMOTE_TESTGIT_REFSPEC-$default_refspec}"
13
14test -z "$refspec" && prefix="refs"
15
16export GIT_DIR="$url/.git"
17
18mkdir -p "$dir"
19
20if test -z "$GIT_REMOTE_TESTGIT_NO_MARKS"
21then
22 gitmarks="$dir/git.marks"
23 testgitmarks="$dir/testgit.marks"
24 test -e "$gitmarks" || >"$gitmarks"
25 test -e "$testgitmarks" || >"$testgitmarks"
26fi
27
28while read line
29do
30 case $line in
31 capabilities)
32 echo 'import'
33 echo 'export'
34 test -n "$refspec" && echo "refspec $refspec"
35 if test -n "$gitmarks"
36 then
37 echo "*import-marks $gitmarks"
38 echo "*export-marks $gitmarks"
39 fi
40 echo
41 ;;
42 list)
43 git for-each-ref --format='? %(refname)' 'refs/heads/'
44 head=$(git symbolic-ref HEAD)
45 echo "@$head HEAD"
46 echo
47 ;;
48 import*)
49 # read all import lines
50 while true
51 do
52 ref="${line#* }"
53 refs="$refs $ref"
54 read line
55 test "${line%% *}" != "import" && break
56 done
57
58 if test -n "$gitmarks"
59 then
60 echo "feature import-marks=$gitmarks"
61 echo "feature export-marks=$gitmarks"
62 fi
63
64 if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
65 then
66 echo "feature done"
67 exit 1
68 fi
69
70 echo "feature done"
71 git fast-export \
72 ${testgitmarks:+"--import-marks=$testgitmarks"} \
73 ${testgitmarks:+"--export-marks=$testgitmarks"} \
74 $refs |
75 sed -e "s#refs/heads/#${prefix}/heads/#g"
76 echo "done"
77 ;;
78 export)
79 if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
80 then
81 # consume input so fast-export doesn't get SIGPIPE;
82 # git would also notice that case, but we want
83 # to make sure we are exercising the later
84 # error checks
85 while read line; do
86 test "done" = "$line" && break
87 done
88 exit 1
89 fi
90
91 before=$(git for-each-ref --format=' %(refname) %(objectname) ')
92
93 git fast-import \
94 ${testgitmarks:+"--import-marks=$testgitmarks"} \
95 ${testgitmarks:+"--export-marks=$testgitmarks"} \
96 --quiet
97
98 # figure out which refs were updated
99 git for-each-ref --format='%(refname) %(objectname)' |
100 while read ref a
101 do
102 case "$before" in
103 *" $ref $a "*)
104 continue ;; # unchanged
105 esac
106 echo "ok $ref"
107 done
108
109 echo
110 ;;
111 '')
112 exit
113 ;;
114 esac
115done