1#!/bin/sh
2# Copyright (c) 2012 Felipe Contreras
34
# 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
7alias=_
8else
9alias=$1
10fi
11url=$2
1213
dir="$GIT_DIR/testgit/$alias"
1415
refspec="refs/heads/*:refs/testgit/$alias/heads/*"
1617
test -n "$GIT_REMOTE_TESTGIT_NOREFSPEC" && refspec=""
1819
GIT_DIR="$url/.git"
20export GIT_DIR
2122
force=
2324
mkdir -p "$dir"
2526
if test -z "$GIT_REMOTE_TESTGIT_NO_MARKS"
27then
28gitmarks="$dir/git.marks"
29testgitmarks="$dir/testgit.marks"
30test -e "$gitmarks" || >"$gitmarks"
31test -e "$testgitmarks" || >"$testgitmarks"
32fi
3334
while read line
35do
36case $line in
37capabilities)
38echo 'import'
39echo 'export'
40test -n "$refspec" && echo "refspec $refspec"
41if test -n "$gitmarks"
42then
43echo "*import-marks $gitmarks"
44echo "*export-marks $gitmarks"
45fi
46test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
47test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update"
48echo 'option'
49echo
50;;
51list)
52git for-each-ref --format='? %(refname)' 'refs/heads/'
53head=$(git symbolic-ref HEAD)
54echo "@$head HEAD"
55echo
56;;
57import*)
58# read all import lines
59while true
60do
61ref="${line#* }"
62refs="$refs $ref"
63read line
64test "${line%% *}" != "import" && break
65done
6667
if test -n "$gitmarks"
68then
69echo "feature import-marks=$gitmarks"
70echo "feature export-marks=$gitmarks"
71fi
7273
if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
74then
75echo "feature done"
76exit 1
77fi
7879
echo "feature done"
80git fast-export \
81${refspec:+"--refspec=$refspec"} \
82${testgitmarks:+"--import-marks=$testgitmarks"} \
83${testgitmarks:+"--export-marks=$testgitmarks"} \
84$refs
85echo "done"
86;;
87export)
88if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
89then
90# consume input so fast-export doesn't get SIGPIPE;
91# git would also notice that case, but we want
92# to make sure we are exercising the later
93# error checks
94while read line; do
95test "done" = "$line" && break
96done
97exit 1
98fi
99100
before=$(git for-each-ref --format=' %(refname) %(objectname) ')
101102
git fast-import \
103${force:+--force} \
104${testgitmarks:+"--import-marks=$testgitmarks"} \
105${testgitmarks:+"--export-marks=$testgitmarks"} \
106--quiet
107108
# figure out which refs were updated
109git for-each-ref --format='%(refname) %(objectname)' |
110while read ref a
111do
112case "$before" in
113*" $ref $a "*)
114continue ;; # unchanged
115esac
116if test -z "$GIT_REMOTE_TESTGIT_PUSH_ERROR"
117then
118echo "ok $ref"
119else
120echo "error $ref $GIT_REMOTE_TESTGIT_PUSH_ERROR"
121fi
122done
123124
echo
125;;
126option\ *)
127read cmd opt val <<-EOF
128$line
129EOF
130case $opt in
131force)
132test $val = "true" && force="true" || force=
133echo "ok"
134;;
135*)
136echo "unsupported"
137;;
138esac
139;;
140'')
141exit
142;;
143esac
144done