Merge git://github.com/git-l10n/git-po
[git/mingw/4msysgit.git] / git-remote-testgit.sh
blob1c006a0518e247d58759df98602f6dae3935caf6
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 force=
20 mkdir -p "$dir"
22 if test -z "$GIT_REMOTE_TESTGIT_NO_MARKS"
23 then
24 gitmarks="$dir/git.marks"
25 testgitmarks="$dir/testgit.marks"
26 test -e "$gitmarks" || >"$gitmarks"
27 test -e "$testgitmarks" || >"$testgitmarks"
30 while read line
32 case $line in
33 capabilities)
34 echo 'import'
35 echo 'export'
36 test -n "$refspec" && echo "refspec $refspec"
37 if test -n "$gitmarks"
38 then
39 echo "*import-marks $gitmarks"
40 echo "*export-marks $gitmarks"
42 test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
43 test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update"
44 echo 'option'
45 echo
47 list)
48 git for-each-ref --format='? %(refname)' 'refs/heads/'
49 head=$(git symbolic-ref HEAD)
50 echo "@$head HEAD"
51 echo
53 import*)
54 # read all import lines
55 while true
57 ref="${line#* }"
58 refs="$refs $ref"
59 read line
60 test "${line%% *}" != "import" && break
61 done
63 if test -n "$gitmarks"
64 then
65 echo "feature import-marks=$gitmarks"
66 echo "feature export-marks=$gitmarks"
69 if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
70 then
71 echo "feature done"
72 exit 1
75 echo "feature done"
76 git fast-export \
77 ${testgitmarks:+"--import-marks=$testgitmarks"} \
78 ${testgitmarks:+"--export-marks=$testgitmarks"} \
79 $refs |
80 sed -e "s#refs/heads/#${prefix}/heads/#g"
81 echo "done"
83 export)
84 if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
85 then
86 # consume input so fast-export doesn't get SIGPIPE;
87 # git would also notice that case, but we want
88 # to make sure we are exercising the later
89 # error checks
90 while read line; do
91 test "done" = "$line" && break
92 done
93 exit 1
96 before=$(git for-each-ref --format=' %(refname) %(objectname) ')
98 git fast-import \
99 ${force:+--force} \
100 ${testgitmarks:+"--import-marks=$testgitmarks"} \
101 ${testgitmarks:+"--export-marks=$testgitmarks"} \
102 --quiet
104 # figure out which refs were updated
105 git for-each-ref --format='%(refname) %(objectname)' |
106 while read ref a
108 case "$before" in
109 *" $ref $a "*)
110 continue ;; # unchanged
111 esac
112 if test -z "$GIT_REMOTE_TESTGIT_PUSH_ERROR"
113 then
114 echo "ok $ref"
115 else
116 echo "error $ref $GIT_REMOTE_TESTGIT_PUSH_ERROR"
118 done
120 echo
122 option\ *)
123 read cmd opt val <<-EOF
124 $line
126 case $opt in
127 force)
128 test $val = "true" && force="true" || force=
129 echo "ok"
132 echo "unsupported"
134 esac
137 exit
139 esac
140 done