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