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