blob: 752c763eb666e197304efbc7ea006325a36ff870 [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
Mike Hommey33cae542015-01-19 10:35:07 +09004# The first argument can be a url when the fetch/push command was a url
5# instead of a configured remote. In this case, use a generic alias.
6if test "$1" = "testgit::$2"; then
7 alias=_
8else
9 alias=$1
10fi
Felipe Contrerasfc407f92012-11-28 23:11:01 +010011url=$2
12
Felipe Contrerasfc407f92012-11-28 23:11:01 +010013dir="$GIT_DIR/testgit/$alias"
14prefix="refs/testgit/$alias"
Felipe Contrerasfc407f92012-11-28 23:11:01 +010015
Felipe Contrerasee10fbf2012-11-28 23:11:05 +010016default_refspec="refs/heads/*:${prefix}/heads/*"
17
18refspec="${GIT_REMOTE_TESTGIT_REFSPEC-$default_refspec}"
19
20test -z "$refspec" && prefix="refs"
Felipe Contrerasfc407f92012-11-28 23:11:01 +010021
Elia Pintobed137d2014-05-23 03:15:31 -070022GIT_DIR="$url/.git"
23export GIT_DIR
Felipe Contrerasfc407f92012-11-28 23:11:01 +010024
Felipe Contreras510fa6f2013-11-12 14:56:56 -060025force=
26
Felipe Contrerasfc407f92012-11-28 23:11:01 +010027mkdir -p "$dir"
28
Felipe Contrerasee10fbf2012-11-28 23:11:05 +010029if test -z "$GIT_REMOTE_TESTGIT_NO_MARKS"
30then
31 gitmarks="$dir/git.marks"
32 testgitmarks="$dir/testgit.marks"
33 test -e "$gitmarks" || >"$gitmarks"
34 test -e "$testgitmarks" || >"$testgitmarks"
Felipe Contrerasee10fbf2012-11-28 23:11:05 +010035fi
Felipe Contrerasfc407f92012-11-28 23:11:01 +010036
37while read line
38do
39 case $line in
40 capabilities)
41 echo 'import'
42 echo 'export'
Felipe Contrerasee10fbf2012-11-28 23:11:05 +010043 test -n "$refspec" && echo "refspec $refspec"
44 if test -n "$gitmarks"
45 then
46 echo "*import-marks $gitmarks"
47 echo "*export-marks $gitmarks"
48 fi
John Keeping0d957a42013-04-14 11:57:08 +010049 test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
Matthieu Moy597b8312013-09-03 17:45:14 +020050 test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update"
Felipe Contreras510fa6f2013-11-12 14:56:56 -060051 echo 'option'
Felipe Contrerasfc407f92012-11-28 23:11:01 +010052 echo
53 ;;
54 list)
55 git for-each-ref --format='? %(refname)' 'refs/heads/'
56 head=$(git symbolic-ref HEAD)
57 echo "@$head HEAD"
58 echo
59 ;;
60 import*)
61 # read all import lines
62 while true
63 do
64 ref="${line#* }"
65 refs="$refs $ref"
66 read line
67 test "${line%% *}" != "import" && break
68 done
69
Felipe Contrerasee10fbf2012-11-28 23:11:05 +010070 if test -n "$gitmarks"
71 then
72 echo "feature import-marks=$gitmarks"
73 echo "feature export-marks=$gitmarks"
74 fi
Felipe Contreras81d340d2013-04-10 17:15:52 -040075
76 if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
77 then
78 echo "feature done"
79 exit 1
80 fi
81
Felipe Contreras1d3f9a32012-11-28 23:11:07 +010082 echo "feature done"
Johannes Sixt85d501c2013-04-25 12:59:41 +020083 git fast-export \
84 ${testgitmarks:+"--import-marks=$testgitmarks"} \
85 ${testgitmarks:+"--export-marks=$testgitmarks"} \
86 $refs |
Felipe Contrerasfc407f92012-11-28 23:11:01 +010087 sed -e "s#refs/heads/#${prefix}/heads/#g"
Felipe Contreras1d3f9a32012-11-28 23:11:07 +010088 echo "done"
Felipe Contrerasfc407f92012-11-28 23:11:01 +010089 ;;
90 export)
Felipe Contreras81d340d2013-04-10 17:15:52 -040091 if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
92 then
93 # consume input so fast-export doesn't get SIGPIPE;
94 # git would also notice that case, but we want
95 # to make sure we are exercising the later
96 # error checks
97 while read line; do
98 test "done" = "$line" && break
99 done
100 exit 1
101 fi
102
Johannes Sixt752db422013-04-27 21:13:13 +0200103 before=$(git for-each-ref --format=' %(refname) %(objectname) ')
Felipe Contreras93b5cf92012-11-28 23:11:06 +0100104
Johannes Sixt85d501c2013-04-25 12:59:41 +0200105 git fast-import \
Felipe Contreras510fa6f2013-11-12 14:56:56 -0600106 ${force:+--force} \
Johannes Sixt85d501c2013-04-25 12:59:41 +0200107 ${testgitmarks:+"--import-marks=$testgitmarks"} \
108 ${testgitmarks:+"--export-marks=$testgitmarks"} \
109 --quiet
Felipe Contreras93b5cf92012-11-28 23:11:06 +0100110
111 # figure out which refs were updated
Johannes Sixt752db422013-04-27 21:13:13 +0200112 git for-each-ref --format='%(refname) %(objectname)' |
113 while read ref a
Felipe Contreras93b5cf92012-11-28 23:11:06 +0100114 do
Johannes Sixt752db422013-04-27 21:13:13 +0200115 case "$before" in
116 *" $ref $a "*)
117 continue ;; # unchanged
118 esac
Felipe Contreras126aac52013-05-10 07:08:30 -0500119 if test -z "$GIT_REMOTE_TESTGIT_PUSH_ERROR"
120 then
121 echo "ok $ref"
122 else
123 echo "error $ref $GIT_REMOTE_TESTGIT_PUSH_ERROR"
124 fi
Felipe Contreras93b5cf92012-11-28 23:11:06 +0100125 done
126
Felipe Contrerasfc407f92012-11-28 23:11:01 +0100127 echo
128 ;;
Felipe Contreras510fa6f2013-11-12 14:56:56 -0600129 option\ *)
130 read cmd opt val <<-EOF
131 $line
132 EOF
133 case $opt in
134 force)
135 test $val = "true" && force="true" || force=
136 echo "ok"
137 ;;
138 *)
139 echo "unsupported"
140 ;;
141 esac
142 ;;
Felipe Contrerasfc407f92012-11-28 23:11:01 +0100143 '')
144 exit
145 ;;
146 esac
147done