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