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