git-remote-testgit: build it to run under $SHELL_PATH
[git/jrn.git] / t / t5801-remote-helpers.sh
blob0a83db8875cc221906ce292dd6247a0323ac6348
1 #!/bin/sh
3 # Copyright (c) 2010 Sverre Rabbelier
6 test_description='Test remote-helper import and export commands'
8 . ./test-lib.sh
10 compare_refs() {
11 git --git-dir="$1/.git" rev-parse --verify $2 >expect &&
12 git --git-dir="$3/.git" rev-parse --verify $4 >actual &&
13 test_cmp expect actual
16 test_expect_success 'setup repository' '
17 git init server &&
18 (cd server &&
19 echo content >file &&
20 git add file &&
21 git commit -m one)
24 test_expect_success 'cloning from local repo' '
25 git clone "testgit::${PWD}/server" local &&
26 test_cmp server/file local/file
29 test_expect_success 'create new commit on remote' '
30 (cd server &&
31 echo content >>file &&
32 git commit -a -m two)
35 test_expect_success 'pulling from local repo' '
36 (cd local && git pull) &&
37 test_cmp server/file local/file
40 test_expect_success 'pushing to local repo' '
41 (cd local &&
42 echo content >>file &&
43 git commit -a -m three &&
44 git push) &&
45 compare_refs local HEAD server HEAD
48 test_expect_success 'fetch new branch' '
49 (cd server &&
50 git reset --hard &&
51 git checkout -b new &&
52 echo content >>file &&
53 git commit -a -m five
54 ) &&
55 (cd local &&
56 git fetch origin new
57 ) &&
58 compare_refs server HEAD local FETCH_HEAD
61 test_expect_success 'fetch multiple branches' '
62 (cd local &&
63 git fetch
64 ) &&
65 compare_refs server master local refs/remotes/origin/master &&
66 compare_refs server new local refs/remotes/origin/new
69 test_expect_success 'push when remote has extra refs' '
70 (cd local &&
71 git reset --hard origin/master &&
72 echo content >>file &&
73 git commit -a -m six &&
74 git push
75 ) &&
76 compare_refs local master server master
79 test_expect_success 'push new branch by name' '
80 (cd local &&
81 git checkout -b new-name &&
82 echo content >>file &&
83 git commit -a -m seven &&
84 git push origin new-name
85 ) &&
86 compare_refs local HEAD server refs/heads/new-name
89 test_expect_failure 'push new branch with old:new refspec' '
90 (cd local &&
91 git push origin new-name:new-refspec
92 ) &&
93 compare_refs local HEAD server refs/heads/new-refspec
96 test_expect_success 'cloning without refspec' '
97 GIT_REMOTE_TESTGIT_REFSPEC="" \
98 git clone "testgit::${PWD}/server" local2 2>error &&
99 grep "This remote helper should implement refspec capability" error &&
100 compare_refs local2 HEAD server HEAD
103 test_expect_success 'pulling without refspecs' '
104 (cd local2 &&
105 git reset --hard &&
106 GIT_REMOTE_TESTGIT_REFSPEC="" git pull 2>../error) &&
107 grep "This remote helper should implement refspec capability" error &&
108 compare_refs local2 HEAD server HEAD
111 test_expect_success 'pushing without refspecs' '
112 test_when_finished "(cd local2 && git reset --hard origin)" &&
113 (cd local2 &&
114 echo content >>file &&
115 git commit -a -m ten &&
116 GIT_REMOTE_TESTGIT_REFSPEC="" &&
117 export GIT_REMOTE_TESTGIT_REFSPEC &&
118 test_must_fail git push 2>../error) &&
119 grep "remote-helper doesn.t support push; refspec needed" error
122 test_expect_success 'pulling without marks' '
123 (cd local2 &&
124 GIT_REMOTE_TESTGIT_NO_MARKS=1 git pull) &&
125 compare_refs local2 HEAD server HEAD
128 test_expect_failure 'pushing without marks' '
129 test_when_finished "(cd local2 && git reset --hard origin)" &&
130 (cd local2 &&
131 echo content >>file &&
132 git commit -a -m twelve &&
133 GIT_REMOTE_TESTGIT_NO_MARKS=1 git push) &&
134 compare_refs local2 HEAD server HEAD
137 test_expect_success 'push all with existing object' '
138 (cd local &&
139 git branch dup2 master &&
140 git push origin --all
141 ) &&
142 compare_refs local dup2 server dup2
145 test_expect_success 'push ref with existing object' '
146 (cd local &&
147 git branch dup master &&
148 git push origin dup
149 ) &&
150 compare_refs local dup server dup
153 test_expect_success 'push update refs' '
154 (cd local &&
155 git checkout -b update master &&
156 echo update >>file &&
157 git commit -a -m update &&
158 git push origin update
159 git rev-parse --verify remotes/origin/update >expect &&
160 git rev-parse --verify testgit/origin/heads/update >actual &&
161 test_cmp expect actual
165 test_expect_success 'proper failure checks for fetching' '
166 (GIT_REMOTE_TESTGIT_FAILURE=1 &&
167 export GIT_REMOTE_TESTGIT_FAILURE &&
168 cd local &&
169 test_must_fail git fetch 2> error &&
170 cat error &&
171 grep -q "Error while running fast-import" error
175 test_expect_success 'proper failure checks for pushing' '
176 (GIT_REMOTE_TESTGIT_FAILURE=1 &&
177 export GIT_REMOTE_TESTGIT_FAILURE &&
178 cd local &&
179 test_must_fail git push --all 2> error &&
180 cat error &&
181 grep -q "Reading from helper .git-remote-testgit. failed" error
185 test_expect_success 'push messages' '
186 (cd local &&
187 git checkout -b new_branch master &&
188 echo new >>file &&
189 git commit -a -m new &&
190 git push origin new_branch &&
191 git fetch origin &&
192 echo new >>file &&
193 git commit -a -m new &&
194 git push origin new_branch 2> msg &&
195 ! grep "\[new branch\]" msg
199 test_done