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