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