]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5801/git-remote-testgit
builtin/clone: allow remote helpers to detect repo
[thirdparty/git.git] / t / t5801 / git-remote-testgit
CommitLineData
85d501ce 1#!/bin/sh
fc407f98
FC
2# Copyright (c) 2012 Felipe Contreras
3
33cae542
MH
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.
6if test "$1" = "testgit::$2"; then
7 alias=_
8else
9 alias=$1
10fi
fc407f98
FC
11url=$2
12
fc407f98 13dir="$GIT_DIR/testgit/$alias"
fc407f98 14
199f44cb
PS
15if ! git rev-parse --is-inside-git-dir
16then
17 exit 1
18fi
19
8144f09c
FC
20h_refspec="refs/heads/*:refs/testgit/$alias/heads/*"
21t_refspec="refs/tags/*:refs/testgit/$alias/tags/*"
ee10fbf9 22
8144f09c
FC
23if test -n "$GIT_REMOTE_TESTGIT_NOREFSPEC"
24then
25 h_refspec=""
26 t_refspec=""
27fi
fc407f98 28
bed137d2
EP
29GIT_DIR="$url/.git"
30export GIT_DIR
fc407f98 31
510fa6f5
FC
32force=
33
fc407f98
FC
34mkdir -p "$dir"
35
ee10fbf9
FC
36if test -z "$GIT_REMOTE_TESTGIT_NO_MARKS"
37then
38 gitmarks="$dir/git.marks"
39 testgitmarks="$dir/testgit.marks"
40 test -e "$gitmarks" || >"$gitmarks"
41 test -e "$testgitmarks" || >"$testgitmarks"
ee10fbf9 42fi
fc407f98
FC
43
44while read line
45do
46 case $line in
47 capabilities)
48 echo 'import'
49 echo 'export'
8144f09c
FC
50 test -n "$h_refspec" && echo "refspec $h_refspec"
51 test -n "$t_refspec" && echo "refspec $t_refspec"
ee10fbf9
FC
52 if test -n "$gitmarks"
53 then
54 echo "*import-marks $gitmarks"
55 echo "*export-marks $gitmarks"
56 fi
0d957a4d 57 test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
597b831a 58 test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update"
510fa6f5 59 echo 'option'
3716d50d 60 echo 'object-format'
fc407f98
FC
61 echo
62 ;;
63 list)
3716d50d 64 echo ":object-format $(git rev-parse --show-object-format=storage)"
8144f09c 65 git for-each-ref --format='? %(refname)' 'refs/heads/' 'refs/tags/'
fc407f98
FC
66 head=$(git symbolic-ref HEAD)
67 echo "@$head HEAD"
68 echo
69 ;;
70 import*)
71 # read all import lines
72 while true
73 do
74 ref="${line#* }"
75 refs="$refs $ref"
76 read line
77 test "${line%% *}" != "import" && break
78 done
79
ee10fbf9
FC
80 if test -n "$gitmarks"
81 then
82 echo "feature import-marks=$gitmarks"
83 echo "feature export-marks=$gitmarks"
84 fi
81d340d4
FC
85
86 if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
87 then
88 echo "feature done"
89 exit 1
90 fi
91
1d3f9a30 92 echo "feature done"
85d501ce 93 git fast-export \
8144f09c
FC
94 ${h_refspec:+"--refspec=$h_refspec"} \
95 ${t_refspec:+"--refspec=$t_refspec"} \
85d501ce
JS
96 ${testgitmarks:+"--import-marks=$testgitmarks"} \
97 ${testgitmarks:+"--export-marks=$testgitmarks"} \
6e17fb34 98 $refs
1d3f9a30 99 echo "done"
fc407f98
FC
100 ;;
101 export)
81d340d4
FC
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
112 fi
113
752db425 114 before=$(git for-each-ref --format=' %(refname) %(objectname) ')
93b5cf9c 115
85d501ce 116 git fast-import \
510fa6f5 117 ${force:+--force} \
85d501ce
JS
118 ${testgitmarks:+"--import-marks=$testgitmarks"} \
119 ${testgitmarks:+"--export-marks=$testgitmarks"} \
120 --quiet
93b5cf9c
FC
121
122 # figure out which refs were updated
752db425
JS
123 git for-each-ref --format='%(refname) %(objectname)' |
124 while read ref a
93b5cf9c 125 do
752db425
JS
126 case "$before" in
127 *" $ref $a "*)
128 continue ;; # unchanged
129 esac
126aac5c
FC
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"
135 fi
93b5cf9c
FC
136 done
137
fc407f98
FC
138 echo
139 ;;
510fa6f5
FC
140 option\ *)
141 read cmd opt val <<-EOF
142 $line
143 EOF
144 case $opt in
145 force)
146 test $val = "true" && force="true" || force=
147 echo "ok"
148 ;;
3716d50d 149 object-format)
150 test $val = "true" && object_format="true" || object_format=
151 echo "ok"
152 ;;
510fa6f5
FC
153 *)
154 echo "unsupported"
155 ;;
156 esac
157 ;;
fc407f98
FC
158 '')
159 exit
160 ;;
161 esac
162done