3 # Copyright (c) 2010 Sverre Rabbelier
6 test_description='Test remote-helper import and export commands'
9 . "$TEST_DIRECTORY"/lib-gpg.sh
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
17 test_expect_success 'setup repository' '
25 test_expect_success 'cloning from local repo' '
26 git clone "testgit::${PWD}/server" local &&
27 test_cmp server/file local/file
30 test_expect_success 'create new commit on remote' '
32 echo content >>file &&
36 test_expect_success 'pulling from local repo' '
37 (cd local && git pull) &&
38 test_cmp server/file local/file
41 test_expect_success 'pushing to local repo' '
43 echo content >>file &&
44 git commit -a -m three &&
46 compare_refs local HEAD server HEAD
49 test_expect_success 'fetch new branch' '
52 git checkout -b new &&
53 echo content >>file &&
59 compare_refs server HEAD local FETCH_HEAD
62 test_expect_success 'fetch multiple branches' '
66 compare_refs server master local refs/remotes/origin/master &&
67 compare_refs server new local refs/remotes/origin/new
70 test_expect_success 'push when remote has extra refs' '
72 git reset --hard origin/master &&
73 echo content >>file &&
74 git commit -a -m six &&
77 compare_refs local master server master
80 test_expect_success 'push new branch by name' '
82 git checkout -b new-name &&
83 echo content >>file &&
84 git commit -a -m seven &&
85 git push origin new-name
87 compare_refs local HEAD server refs/heads/new-name
90 test_expect_success 'push new branch with old:new refspec' '
92 git push origin new-name:new-refspec
94 compare_refs local HEAD server refs/heads/new-refspec
97 test_expect_success 'push new branch with HEAD:new refspec' '
100 git push origin HEAD:new-refspec-2
102 compare_refs local HEAD server refs/heads/new-refspec-2
105 test_expect_success 'push delete branch' '
107 git push origin :new-name
109 test_must_fail git --git-dir="server/.git" \
110 rev-parse --verify refs/heads/new-name
113 test_expect_success 'forced push' '
115 git checkout -b force-test &&
116 echo content >> file &&
117 git commit -a -m eight &&
118 git push origin force-test &&
119 echo content >> file &&
120 git commit -a --amend -m eight-modified &&
121 git push --force origin force-test
123 compare_refs local refs/heads/force-test server refs/heads/force-test
126 test_expect_success 'cloning without refspec' '
127 GIT_REMOTE_TESTGIT_REFSPEC="" \
128 git clone "testgit::${PWD}/server" local2 2>error &&
129 grep "This remote helper should implement refspec capability" error &&
130 compare_refs local2 HEAD server HEAD
133 test_expect_success 'pulling without refspecs' '
136 GIT_REMOTE_TESTGIT_REFSPEC="" git pull 2>../error) &&
137 grep "This remote helper should implement refspec capability" error &&
138 compare_refs local2 HEAD server HEAD
141 test_expect_success 'pushing without refspecs' '
142 test_when_finished "(cd local2 && git reset --hard origin)" &&
144 echo content >>file &&
145 git commit -a -m ten &&
146 GIT_REMOTE_TESTGIT_REFSPEC="" &&
147 export GIT_REMOTE_TESTGIT_REFSPEC &&
148 test_must_fail git push 2>../error) &&
149 grep "remote-helper doesn.t support push; refspec needed" error
152 test_expect_success 'pulling without marks' '
154 GIT_REMOTE_TESTGIT_NO_MARKS=1 git pull) &&
155 compare_refs local2 HEAD server HEAD
158 test_expect_failure 'pushing without marks' '
159 test_when_finished "(cd local2 && git reset --hard origin)" &&
161 echo content >>file &&
162 git commit -a -m twelve &&
163 GIT_REMOTE_TESTGIT_NO_MARKS=1 git push) &&
164 compare_refs local2 HEAD server HEAD
167 test_expect_success 'push all with existing object' '
169 git branch dup2 master &&
170 git push origin --all
172 compare_refs local dup2 server dup2
175 test_expect_success 'push ref with existing object' '
177 git branch dup master &&
180 compare_refs local dup server dup
183 test_expect_success GPG 'push signed tag' '
185 git checkout master &&
186 git tag -s -m signed-tag signed-tag &&
187 git push origin signed-tag
189 compare_refs local signed-tag^{} server signed-tag^{} &&
190 test_must_fail compare_refs local signed-tag server signed-tag
193 test_expect_success GPG 'push signed tag with signed-tags capability' '
195 git checkout master &&
196 git tag -s -m signed-tag signed-tag-2 &&
197 GIT_REMOTE_TESTGIT_SIGNED_TAGS=1 git push origin signed-tag-2
199 compare_refs local signed-tag-2 server signed-tag-2
202 test_expect_success 'push update refs' '
204 git checkout -b update master &&
205 echo update >>file &&
206 git commit -a -m update &&
207 git push origin update &&
208 git rev-parse --verify remotes/origin/update >expect &&
209 git rev-parse --verify testgit/origin/heads/update >actual &&
210 test_cmp expect actual
214 test_expect_success 'push update refs disabled by no-private-update' '
216 echo more-update >>file &&
217 git commit -a -m more-update &&
218 git rev-parse --verify testgit/origin/heads/update >expect &&
219 GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE=t git push origin update &&
220 git rev-parse --verify testgit/origin/heads/update >actual &&
221 test_cmp expect actual
225 test_expect_success 'push update refs failure' '
227 git checkout update &&
228 echo "update fail" >>file &&
229 git commit -a -m "update fail" &&
230 git rev-parse --verify testgit/origin/heads/update >expect &&
231 test_expect_code 1 env GIT_REMOTE_TESTGIT_FAILURE="non-fast forward" \
232 git push origin update &&
233 git rev-parse --verify testgit/origin/heads/update >actual &&
234 test_cmp expect actual
239 cut -f 2 -d ' ' "$1" |
240 git cat-file --batch-check |
242 sort >$(basename "$1")
246 test_when_finished "rm -rf git.marks testgit.marks" &&
247 clean_mark ".git/testgit/$1/git.marks" &&
248 clean_mark ".git/testgit/$1/testgit.marks" &&
249 test_cmp git.marks testgit.marks
252 test_expect_success 'proper failure checks for fetching' '
254 test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git fetch 2>error &&
256 grep -q "Error while running fast-import" error
260 test_expect_success 'proper failure checks for pushing' '
262 git checkout -b crash master &&
264 git commit -a -m crash &&
265 test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git push --all &&
270 test_expect_success 'push messages' '
272 git checkout -b new_branch master &&
274 git commit -a -m new &&
275 git push origin new_branch &&
278 git commit -a -m new &&
279 git push origin new_branch 2> msg &&
280 ! grep "\[new branch\]" msg