]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5801/git-remote-testgit
bundle: detect hash algorithm when reading refs
[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
8144f09c
FC
15h_refspec="refs/heads/*:refs/testgit/$alias/heads/*"
16t_refspec="refs/tags/*:refs/testgit/$alias/tags/*"
ee10fbf9 17
8144f09c
FC
18if test -n "$GIT_REMOTE_TESTGIT_NOREFSPEC"
19then
20 h_refspec=""
21 t_refspec=""
22fi
fc407f98 23
bed137d2
EP
24GIT_DIR="$url/.git"
25export GIT_DIR
fc407f98 26
510fa6f5
FC
27force=
28
fc407f98
FC
29mkdir -p "$dir"
30
ee10fbf9
FC
31if test -z "$GIT_REMOTE_TESTGIT_NO_MARKS"
32then
33 gitmarks="$dir/git.marks"
34 testgitmarks="$dir/testgit.marks"
35 test -e "$gitmarks" || >"$gitmarks"
36 test -e "$testgitmarks" || >"$testgitmarks"
ee10fbf9 37fi
fc407f98
FC
38
39while read line
40do
41 case $line in
42 capabilities)
43 echo 'import'
44 echo 'export'
8144f09c
FC
45 test -n "$h_refspec" && echo "refspec $h_refspec"
46 test -n "$t_refspec" && echo "refspec $t_refspec"
ee10fbf9
FC
47 if test -n "$gitmarks"
48 then
49 echo "*import-marks $gitmarks"
50 echo "*export-marks $gitmarks"
51 fi
0d957a4d 52 test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
597b831a 53 test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update"
510fa6f5 54 echo 'option'
fc407f98
FC
55 echo
56 ;;
57 list)
8144f09c 58 git for-each-ref --format='? %(refname)' 'refs/heads/' 'refs/tags/'
fc407f98
FC
59 head=$(git symbolic-ref HEAD)
60 echo "@$head HEAD"
61 echo
62 ;;
63 import*)
64 # read all import lines
65 while true
66 do
67 ref="${line#* }"
68 refs="$refs $ref"
69 read line
70 test "${line%% *}" != "import" && break
71 done
72
ee10fbf9
FC
73 if test -n "$gitmarks"
74 then
75 echo "feature import-marks=$gitmarks"
76 echo "feature export-marks=$gitmarks"
77 fi
81d340d4
FC
78
79 if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
80 then
81 echo "feature done"
82 exit 1
83 fi
84
1d3f9a30 85 echo "feature done"
85d501ce 86 git fast-export \
8144f09c
FC
87 ${h_refspec:+"--refspec=$h_refspec"} \
88 ${t_refspec:+"--refspec=$t_refspec"} \
85d501ce
JS
89 ${testgitmarks:+"--import-marks=$testgitmarks"} \
90 ${testgitmarks:+"--export-marks=$testgitmarks"} \
6e17fb34 91 $refs
1d3f9a30 92 echo "done"
fc407f98
FC
93 ;;
94 export)
81d340d4
FC
95 if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
96 then
97 # consume input so fast-export doesn't get SIGPIPE;
98 # git would also notice that case, but we want
99 # to make sure we are exercising the later
100 # error checks
101 while read line; do
102 test "done" = "$line" && break
103 done
104 exit 1
105 fi
106
752db425 107 before=$(git for-each-ref --format=' %(refname) %(objectname) ')
93b5cf9c 108
85d501ce 109 git fast-import \
510fa6f5 110 ${force:+--force} \
85d501ce
JS
111 ${testgitmarks:+"--import-marks=$testgitmarks"} \
112 ${testgitmarks:+"--export-marks=$testgitmarks"} \
113 --quiet
93b5cf9c
FC
114
115 # figure out which refs were updated
752db425
JS
116 git for-each-ref --format='%(refname) %(objectname)' |
117 while read ref a
93b5cf9c 118 do
752db425
JS
119 case "$before" in
120 *" $ref $a "*)
121 continue ;; # unchanged
122 esac
126aac5c
FC
123 if test -z "$GIT_REMOTE_TESTGIT_PUSH_ERROR"
124 then
125 echo "ok $ref"
126 else
127 echo "error $ref $GIT_REMOTE_TESTGIT_PUSH_ERROR"
128 fi
93b5cf9c
FC
129 done
130
fc407f98
FC
131 echo
132 ;;
510fa6f5
FC
133 option\ *)
134 read cmd opt val <<-EOF
135 $line
136 EOF
137 case $opt in
138 force)
139 test $val = "true" && force="true" || force=
140 echo "ok"
141 ;;
142 *)
143 echo "unsupported"
144 ;;
145 esac
146 ;;
fc407f98
FC
147 '')
148 exit
149 ;;
150 esac
151done