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