]>
Commit | Line | Data |
---|---|---|
fc407f98 FC |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2010 Sverre Rabbelier | |
4 | # | |
5 | ||
6 | test_description='Test remote-helper import and export commands' | |
7 | ||
8 | . ./test-lib.sh | |
b8bd826f | 9 | . "$TEST_DIRECTORY"/lib-gpg.sh |
fc407f98 | 10 | |
fc407f98 FC |
11 | compare_refs() { |
12 | git --git-dir="$1/.git" rev-parse --verify $2 >expect && | |
13 | git --git-dir="$3/.git" rev-parse --verify $4 >actual && | |
14 | test_cmp expect actual | |
15 | } | |
16 | ||
17 | test_expect_success 'setup repository' ' | |
3808b851 FC |
18 | git init server && |
19 | (cd server && | |
fc407f98 FC |
20 | echo content >file && |
21 | git add file && | |
3808b851 | 22 | git commit -m one) |
fc407f98 FC |
23 | ' |
24 | ||
25 | test_expect_success 'cloning from local repo' ' | |
3808b851 FC |
26 | git clone "testgit::${PWD}/server" local && |
27 | test_cmp server/file local/file | |
fc407f98 FC |
28 | ' |
29 | ||
fc407f98 | 30 | test_expect_success 'create new commit on remote' ' |
3808b851 | 31 | (cd server && |
fc407f98 | 32 | echo content >>file && |
3808b851 | 33 | git commit -a -m two) |
fc407f98 FC |
34 | ' |
35 | ||
36 | test_expect_success 'pulling from local repo' ' | |
3808b851 FC |
37 | (cd local && git pull) && |
38 | test_cmp server/file local/file | |
fc407f98 FC |
39 | ' |
40 | ||
fc407f98 | 41 | test_expect_success 'pushing to local repo' ' |
3808b851 | 42 | (cd local && |
fc407f98 FC |
43 | echo content >>file && |
44 | git commit -a -m three && | |
45 | git push) && | |
3808b851 | 46 | compare_refs local HEAD server HEAD |
fc407f98 FC |
47 | ' |
48 | ||
fc407f98 | 49 | test_expect_success 'fetch new branch' ' |
3808b851 FC |
50 | (cd server && |
51 | git reset --hard && | |
fc407f98 FC |
52 | git checkout -b new && |
53 | echo content >>file && | |
3808b851 | 54 | git commit -a -m five |
fc407f98 | 55 | ) && |
3808b851 | 56 | (cd local && |
fc407f98 FC |
57 | git fetch origin new |
58 | ) && | |
3808b851 | 59 | compare_refs server HEAD local FETCH_HEAD |
fc407f98 FC |
60 | ' |
61 | ||
62 | test_expect_success 'fetch multiple branches' ' | |
3808b851 | 63 | (cd local && |
fc407f98 FC |
64 | git fetch |
65 | ) && | |
3808b851 FC |
66 | compare_refs server master local refs/remotes/origin/master && |
67 | compare_refs server new local refs/remotes/origin/new | |
fc407f98 FC |
68 | ' |
69 | ||
70 | test_expect_success 'push when remote has extra refs' ' | |
3808b851 | 71 | (cd local && |
984f3768 | 72 | git reset --hard origin/master && |
fc407f98 FC |
73 | echo content >>file && |
74 | git commit -a -m six && | |
75 | git push | |
76 | ) && | |
3808b851 | 77 | compare_refs local master server master |
fc407f98 FC |
78 | ' |
79 | ||
80 | test_expect_success 'push new branch by name' ' | |
3808b851 | 81 | (cd local && |
fc407f98 FC |
82 | git checkout -b new-name && |
83 | echo content >>file && | |
84 | git commit -a -m seven && | |
85 | git push origin new-name | |
86 | ) && | |
3808b851 | 87 | compare_refs local HEAD server refs/heads/new-name |
fc407f98 FC |
88 | ' |
89 | ||
90 | test_expect_failure 'push new branch with old:new refspec' ' | |
3808b851 | 91 | (cd local && |
fc407f98 FC |
92 | git push origin new-name:new-refspec |
93 | ) && | |
3808b851 | 94 | compare_refs local HEAD server refs/heads/new-refspec |
fc407f98 FC |
95 | ' |
96 | ||
ee10fbf9 FC |
97 | test_expect_success 'cloning without refspec' ' |
98 | GIT_REMOTE_TESTGIT_REFSPEC="" \ | |
a93b4a09 FC |
99 | git clone "testgit::${PWD}/server" local2 2>error && |
100 | grep "This remote helper should implement refspec capability" error && | |
ee10fbf9 FC |
101 | compare_refs local2 HEAD server HEAD |
102 | ' | |
103 | ||
104 | test_expect_success 'pulling without refspecs' ' | |
105 | (cd local2 && | |
106 | git reset --hard && | |
a93b4a09 FC |
107 | GIT_REMOTE_TESTGIT_REFSPEC="" git pull 2>../error) && |
108 | grep "This remote helper should implement refspec capability" error && | |
ee10fbf9 FC |
109 | compare_refs local2 HEAD server HEAD |
110 | ' | |
111 | ||
21610d82 | 112 | test_expect_success 'pushing without refspecs' ' |
ee10fbf9 FC |
113 | test_when_finished "(cd local2 && git reset --hard origin)" && |
114 | (cd local2 && | |
115 | echo content >>file && | |
116 | git commit -a -m ten && | |
1afe6e40 JH |
117 | GIT_REMOTE_TESTGIT_REFSPEC="" && |
118 | export GIT_REMOTE_TESTGIT_REFSPEC && | |
119 | test_must_fail git push 2>../error) && | |
21610d82 | 120 | grep "remote-helper doesn.t support push; refspec needed" error |
ee10fbf9 FC |
121 | ' |
122 | ||
123 | test_expect_success 'pulling without marks' ' | |
124 | (cd local2 && | |
125 | GIT_REMOTE_TESTGIT_NO_MARKS=1 git pull) && | |
126 | compare_refs local2 HEAD server HEAD | |
127 | ' | |
128 | ||
129 | test_expect_failure 'pushing without marks' ' | |
130 | test_when_finished "(cd local2 && git reset --hard origin)" && | |
131 | (cd local2 && | |
132 | echo content >>file && | |
133 | git commit -a -m twelve && | |
134 | GIT_REMOTE_TESTGIT_NO_MARKS=1 git push) && | |
135 | compare_refs local2 HEAD server HEAD | |
136 | ' | |
137 | ||
49266e8a FC |
138 | test_expect_success 'push all with existing object' ' |
139 | (cd local && | |
140 | git branch dup2 master && | |
141 | git push origin --all | |
142 | ) && | |
143 | compare_refs local dup2 server dup2 | |
144 | ' | |
145 | ||
f28e7c90 FC |
146 | test_expect_success 'push ref with existing object' ' |
147 | (cd local && | |
148 | git branch dup master && | |
149 | git push origin dup | |
150 | ) && | |
151 | compare_refs local dup server dup | |
152 | ' | |
153 | ||
b8bd826f JK |
154 | test_expect_success GPG 'push signed tag' ' |
155 | (cd local && | |
156 | git checkout master && | |
157 | git tag -s -m signed-tag signed-tag && | |
158 | git push origin signed-tag | |
159 | ) && | |
0d957a4d JK |
160 | compare_refs local signed-tag^{} server signed-tag^{} && |
161 | test_must_fail compare_refs local signed-tag server signed-tag | |
162 | ' | |
163 | ||
164 | test_expect_success GPG 'push signed tag with signed-tags capability' ' | |
165 | (cd local && | |
166 | git checkout master && | |
167 | git tag -s -m signed-tag signed-tag-2 && | |
168 | GIT_REMOTE_TESTGIT_SIGNED_TAGS=1 git push origin signed-tag-2 | |
169 | ) && | |
170 | compare_refs local signed-tag-2 server signed-tag-2 | |
b8bd826f JK |
171 | ' |
172 | ||
664059fb FC |
173 | test_expect_success 'push update refs' ' |
174 | (cd local && | |
175 | git checkout -b update master && | |
176 | echo update >>file && | |
177 | git commit -a -m update && | |
d6ae7b2d | 178 | git push origin update && |
664059fb FC |
179 | git rev-parse --verify remotes/origin/update >expect && |
180 | git rev-parse --verify testgit/origin/heads/update >actual && | |
181 | test_cmp expect actual | |
182 | ) | |
183 | ' | |
184 | ||
597b831a MM |
185 | test_expect_success 'push update refs disabled by no-private-update' ' |
186 | (cd local && | |
187 | echo more-update >>file && | |
188 | git commit -a -m more-update && | |
189 | git rev-parse --verify testgit/origin/heads/update >expect && | |
190 | GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE=t git push origin update && | |
191 | git rev-parse --verify testgit/origin/heads/update >actual && | |
192 | test_cmp expect actual | |
193 | ) | |
194 | ' | |
195 | ||
126aac5c FC |
196 | test_expect_success 'push update refs failure' ' |
197 | (cd local && | |
198 | git checkout update && | |
199 | echo "update fail" >>file && | |
200 | git commit -a -m "update fail" && | |
201 | git rev-parse --verify testgit/origin/heads/update >expect && | |
202 | GIT_REMOTE_TESTGIT_PUSH_ERROR="non-fast forward" && | |
203 | export GIT_REMOTE_TESTGIT_PUSH_ERROR && | |
204 | test_expect_code 1 git push origin update && | |
205 | git rev-parse --verify testgit/origin/heads/update >actual && | |
206 | test_cmp expect actual | |
207 | ) | |
208 | ' | |
209 | ||
81d340d4 FC |
210 | test_expect_success 'proper failure checks for fetching' ' |
211 | (GIT_REMOTE_TESTGIT_FAILURE=1 && | |
212 | export GIT_REMOTE_TESTGIT_FAILURE && | |
213 | cd local && | |
214 | test_must_fail git fetch 2> error && | |
215 | cat error && | |
216 | grep -q "Error while running fast-import" error | |
217 | ) | |
218 | ' | |
219 | ||
220 | test_expect_success 'proper failure checks for pushing' ' | |
221 | (GIT_REMOTE_TESTGIT_FAILURE=1 && | |
222 | export GIT_REMOTE_TESTGIT_FAILURE && | |
223 | cd local && | |
266f1fdf | 224 | test_must_fail git push --all |
81d340d4 FC |
225 | ) |
226 | ' | |
227 | ||
b056620f FC |
228 | test_expect_success 'push messages' ' |
229 | (cd local && | |
230 | git checkout -b new_branch master && | |
231 | echo new >>file && | |
232 | git commit -a -m new && | |
233 | git push origin new_branch && | |
234 | git fetch origin && | |
235 | echo new >>file && | |
236 | git commit -a -m new && | |
237 | git push origin new_branch 2> msg && | |
238 | ! grep "\[new branch\]" msg | |
239 | ) | |
240 | ' | |
241 | ||
fc407f98 | 242 | test_done |