builtin/clone: allow remote helpers to detect repo
[alt-git.git] / t / t5801 / git-remote-testgit
blobbcfb358c51cc087efd75aa04488f9b16a75e7293
1 #!/bin/sh
2 # Copyright (c) 2012 Felipe Contreras
4 # 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.
6 if test "$1" = "testgit::$2"; then
7 alias=_
8 else
9 alias=$1
11 url=$2
13 dir="$GIT_DIR/testgit/$alias"
15 if ! git rev-parse --is-inside-git-dir
16 then
17 exit 1
20 h_refspec="refs/heads/*:refs/testgit/$alias/heads/*"
21 t_refspec="refs/tags/*:refs/testgit/$alias/tags/*"
23 if test -n "$GIT_REMOTE_TESTGIT_NOREFSPEC"
24 then
25 h_refspec=""
26 t_refspec=""
29 GIT_DIR="$url/.git"
30 export GIT_DIR
32 force=
34 mkdir -p "$dir"
36 if test -z "$GIT_REMOTE_TESTGIT_NO_MARKS"
37 then
38 gitmarks="$dir/git.marks"
39 testgitmarks="$dir/testgit.marks"
40 test -e "$gitmarks" || >"$gitmarks"
41 test -e "$testgitmarks" || >"$testgitmarks"
44 while read line
46 case $line in
47 capabilities)
48 echo 'import'
49 echo 'export'
50 test -n "$h_refspec" && echo "refspec $h_refspec"
51 test -n "$t_refspec" && echo "refspec $t_refspec"
52 if test -n "$gitmarks"
53 then
54 echo "*import-marks $gitmarks"
55 echo "*export-marks $gitmarks"
57 test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
58 test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update"
59 echo 'option'
60 echo 'object-format'
61 echo
63 list)
64 echo ":object-format $(git rev-parse --show-object-format=storage)"
65 git for-each-ref --format='? %(refname)' 'refs/heads/' 'refs/tags/'
66 head=$(git symbolic-ref HEAD)
67 echo "@$head HEAD"
68 echo
70 import*)
71 # read all import lines
72 while true
74 ref="${line#* }"
75 refs="$refs $ref"
76 read line
77 test "${line%% *}" != "import" && break
78 done
80 if test -n "$gitmarks"
81 then
82 echo "feature import-marks=$gitmarks"
83 echo "feature export-marks=$gitmarks"
86 if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
87 then
88 echo "feature done"
89 exit 1
92 echo "feature done"
93 git fast-export \
94 ${h_refspec:+"--refspec=$h_refspec"} \
95 ${t_refspec:+"--refspec=$t_refspec"} \
96 ${testgitmarks:+"--import-marks=$testgitmarks"} \
97 ${testgitmarks:+"--export-marks=$testgitmarks"} \
98 $refs
99 echo "done"
101 export)
102 if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
103 then
104 # consume input so fast-export doesn't get SIGPIPE;
105 # git would also notice that case, but we want
106 # to make sure we are exercising the later
107 # error checks
108 while read line; do
109 test "done" = "$line" && break
110 done
111 exit 1
114 before=$(git for-each-ref --format=' %(refname) %(objectname) ')
116 git fast-import \
117 ${force:+--force} \
118 ${testgitmarks:+"--import-marks=$testgitmarks"} \
119 ${testgitmarks:+"--export-marks=$testgitmarks"} \
120 --quiet
122 # figure out which refs were updated
123 git for-each-ref --format='%(refname) %(objectname)' |
124 while read ref a
126 case "$before" in
127 *" $ref $a "*)
128 continue ;; # unchanged
129 esac
130 if test -z "$GIT_REMOTE_TESTGIT_PUSH_ERROR"
131 then
132 echo "ok $ref"
133 else
134 echo "error $ref $GIT_REMOTE_TESTGIT_PUSH_ERROR"
136 done
138 echo
140 option\ *)
141 read cmd opt val <<-EOF
142 $line
144 case $opt in
145 force)
146 test $val = "true" && force="true" || force=
147 echo "ok"
149 object-format)
150 test $val = "true" && object_format="true" || object_format=
151 echo "ok"
154 echo "unsupported"
156 esac
159 exit
161 esac
162 done