blob: 6d2f282d32212b605a1237bae224ecbba05cacd1 [file] [log] [blame]
Johannes Sixt85d501c2013-04-25 12:59:41 +02001#!/bin/sh
Felipe Contrerasfc407f92012-11-28 23:11:01 +01002# Copyright (c) 2012 Felipe Contreras
3
4alias=$1
5url=$2
6
Felipe Contrerasfc407f92012-11-28 23:11:01 +01007dir="$GIT_DIR/testgit/$alias"
8prefix="refs/testgit/$alias"
Felipe Contrerasfc407f92012-11-28 23:11:01 +01009
Felipe Contrerasee10fbf2012-11-28 23:11:05 +010010default_refspec="refs/heads/*:${prefix}/heads/*"
11
12refspec="${GIT_REMOTE_TESTGIT_REFSPEC-$default_refspec}"
13
14test -z "$refspec" && prefix="refs"
Felipe Contrerasfc407f92012-11-28 23:11:01 +010015
16export GIT_DIR="$url/.git"
17
18mkdir -p "$dir"
19
Felipe Contrerasee10fbf2012-11-28 23:11:05 +010020if 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"
Felipe Contrerasee10fbf2012-11-28 23:11:05 +010026fi
Felipe Contrerasfc407f92012-11-28 23:11:01 +010027
28while read line
29do
30 case $line in
31 capabilities)
32 echo 'import'
33 echo 'export'
Felipe Contrerasee10fbf2012-11-28 23:11:05 +010034 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
John Keeping0d957a42013-04-14 11:57:08 +010040 test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
Matthieu Moy597b8312013-09-03 17:45:14 +020041 test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update"
Felipe Contrerasfc407f92012-11-28 23:11:01 +010042 echo
43 ;;
44 list)
45 git for-each-ref --format='? %(refname)' 'refs/heads/'
46 head=$(git symbolic-ref HEAD)
47 echo "@$head HEAD"
48 echo
49 ;;
50 import*)
51 # read all import lines
52 while true
53 do
54 ref="${line#* }"
55 refs="$refs $ref"
56 read line
57 test "${line%% *}" != "import" && break
58 done
59
Felipe Contrerasee10fbf2012-11-28 23:11:05 +010060 if test -n "$gitmarks"
61 then
62 echo "feature import-marks=$gitmarks"
63 echo "feature export-marks=$gitmarks"
64 fi
Felipe Contreras81d340d2013-04-10 17:15:52 -040065
66 if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
67 then
68 echo "feature done"
69 exit 1
70 fi
71
Felipe Contreras1d3f9a32012-11-28 23:11:07 +010072 echo "feature done"
Johannes Sixt85d501c2013-04-25 12:59:41 +020073 git fast-export \
74 ${testgitmarks:+"--import-marks=$testgitmarks"} \
75 ${testgitmarks:+"--export-marks=$testgitmarks"} \
76 $refs |
Felipe Contrerasfc407f92012-11-28 23:11:01 +010077 sed -e "s#refs/heads/#${prefix}/heads/#g"
Felipe Contreras1d3f9a32012-11-28 23:11:07 +010078 echo "done"
Felipe Contrerasfc407f92012-11-28 23:11:01 +010079 ;;
80 export)
Felipe Contreras81d340d2013-04-10 17:15:52 -040081 if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
82 then
83 # consume input so fast-export doesn't get SIGPIPE;
84 # git would also notice that case, but we want
85 # to make sure we are exercising the later
86 # error checks
87 while read line; do
88 test "done" = "$line" && break
89 done
90 exit 1
91 fi
92
Johannes Sixt752db422013-04-27 21:13:13 +020093 before=$(git for-each-ref --format=' %(refname) %(objectname) ')
Felipe Contreras93b5cf92012-11-28 23:11:06 +010094
Johannes Sixt85d501c2013-04-25 12:59:41 +020095 git fast-import \
96 ${testgitmarks:+"--import-marks=$testgitmarks"} \
97 ${testgitmarks:+"--export-marks=$testgitmarks"} \
98 --quiet
Felipe Contreras93b5cf92012-11-28 23:11:06 +010099
100 # figure out which refs were updated
Johannes Sixt752db422013-04-27 21:13:13 +0200101 git for-each-ref --format='%(refname) %(objectname)' |
102 while read ref a
Felipe Contreras93b5cf92012-11-28 23:11:06 +0100103 do
Johannes Sixt752db422013-04-27 21:13:13 +0200104 case "$before" in
105 *" $ref $a "*)
106 continue ;; # unchanged
107 esac
Felipe Contreras126aac52013-05-10 07:08:30 -0500108 if test -z "$GIT_REMOTE_TESTGIT_PUSH_ERROR"
109 then
110 echo "ok $ref"
111 else
112 echo "error $ref $GIT_REMOTE_TESTGIT_PUSH_ERROR"
113 fi
Felipe Contreras93b5cf92012-11-28 23:11:06 +0100114 done
115
Felipe Contrerasfc407f92012-11-28 23:11:01 +0100116 echo
117 ;;
118 '')
119 exit
120 ;;
121 esac
122done