git-remote-testgit: build it to run under $SHELL_PATH
[git/jrn.git] / git-remote-testgit.sh
blobb5289493e2ca84bbbff58734bcb0abcae2145312
1 #!/bin/sh
2 # Copyright (c) 2012 Felipe Contreras
4 alias=$1
5 url=$2
7 dir="$GIT_DIR/testgit/$alias"
8 prefix="refs/testgit/$alias"
10 default_refspec="refs/heads/*:${prefix}/heads/*"
12 refspec="${GIT_REMOTE_TESTGIT_REFSPEC-$default_refspec}"
14 test -z "$refspec" && prefix="refs"
16 export GIT_DIR="$url/.git"
18 mkdir -p "$dir"
20 if test -z "$GIT_REMOTE_TESTGIT_NO_MARKS"
21 then
22 gitmarks="$dir/git.marks"
23 testgitmarks="$dir/testgit.marks"
24 test -e "$gitmarks" || >"$gitmarks"
25 test -e "$testgitmarks" || >"$testgitmarks"
28 while read line
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"
40 echo
42 list)
43 git for-each-ref --format='? %(refname)' 'refs/heads/'
44 head=$(git symbolic-ref HEAD)
45 echo "@$head HEAD"
46 echo
48 import*)
49 # read all import lines
50 while true
52 ref="${line#* }"
53 refs="$refs $ref"
54 read line
55 test "${line%% *}" != "import" && break
56 done
58 if test -n "$gitmarks"
59 then
60 echo "feature import-marks=$gitmarks"
61 echo "feature export-marks=$gitmarks"
64 if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
65 then
66 echo "feature done"
67 exit 1
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"
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
91 before=$(git for-each-ref --format=' %(refname) %(objectname) ')
93 git fast-import \
94 ${testgitmarks:+"--import-marks=$testgitmarks"} \
95 ${testgitmarks:+"--export-marks=$testgitmarks"} \
96 --quiet
98 # figure out which refs were updated
99 git for-each-ref --format='%(refname) %(objectname)' |
100 while read ref a
102 case "$before" in
103 *" $ref $a "*)
104 continue ;; # unchanged
105 esac
106 echo "ok $ref"
107 done
109 echo
112 exit
114 esac
115 done