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