t5801: "VAR=VAL shell_func args" is forbidden
[git/mingw.git] / t / t5801-remote-helpers.sh
blobc956abd865b7149742ed85203b3ba73c42b0b39b
1 #!/bin/sh
3 # Copyright (c) 2010 Sverre Rabbelier
6 test_description='Test remote-helper import and export commands'
8 . ./test-lib.sh
10 if ! type "${BASH-bash}" >/dev/null 2>&1; then
11 skip_all='skipping remote-testgit tests, bash not available'
12 test_done
15 compare_refs() {
16 git --git-dir="$1/.git" rev-parse --verify $2 >expect &&
17 git --git-dir="$3/.git" rev-parse --verify $4 >actual &&
18 test_cmp expect actual
21 test_expect_success 'setup repository' '
22 git init server &&
23 (cd server &&
24 echo content >file &&
25 git add file &&
26 git commit -m one)
29 test_expect_success 'cloning from local repo' '
30 git clone "testgit::${PWD}/server" local &&
31 test_cmp server/file local/file
34 test_expect_success 'create new commit on remote' '
35 (cd server &&
36 echo content >>file &&
37 git commit -a -m two)
40 test_expect_success 'pulling from local repo' '
41 (cd local && git pull) &&
42 test_cmp server/file local/file
45 test_expect_success 'pushing to local repo' '
46 (cd local &&
47 echo content >>file &&
48 git commit -a -m three &&
49 git push) &&
50 compare_refs local HEAD server HEAD
53 test_expect_success 'fetch new branch' '
54 (cd server &&
55 git reset --hard &&
56 git checkout -b new &&
57 echo content >>file &&
58 git commit -a -m five
59 ) &&
60 (cd local &&
61 git fetch origin new
62 ) &&
63 compare_refs server HEAD local FETCH_HEAD
66 test_expect_success 'fetch multiple branches' '
67 (cd local &&
68 git fetch
69 ) &&
70 compare_refs server master local refs/remotes/origin/master &&
71 compare_refs server new local refs/remotes/origin/new
74 test_expect_success 'push when remote has extra refs' '
75 (cd local &&
76 git reset --hard origin/master &&
77 echo content >>file &&
78 git commit -a -m six &&
79 git push
80 ) &&
81 compare_refs local master server master
84 test_expect_success 'push new branch by name' '
85 (cd local &&
86 git checkout -b new-name &&
87 echo content >>file &&
88 git commit -a -m seven &&
89 git push origin new-name
90 ) &&
91 compare_refs local HEAD server refs/heads/new-name
94 test_expect_failure 'push new branch with old:new refspec' '
95 (cd local &&
96 git push origin new-name:new-refspec
97 ) &&
98 compare_refs local HEAD server refs/heads/new-refspec
101 test_expect_success 'cloning without refspec' '
102 GIT_REMOTE_TESTGIT_REFSPEC="" \
103 git clone "testgit::${PWD}/server" local2 2>error &&
104 grep "This remote helper should implement refspec capability" error &&
105 compare_refs local2 HEAD server HEAD
108 test_expect_success 'pulling without refspecs' '
109 (cd local2 &&
110 git reset --hard &&
111 GIT_REMOTE_TESTGIT_REFSPEC="" git pull 2>../error) &&
112 grep "This remote helper should implement refspec capability" error &&
113 compare_refs local2 HEAD server HEAD
116 test_expect_success 'pushing without refspecs' '
117 test_when_finished "(cd local2 && git reset --hard origin)" &&
118 (cd local2 &&
119 echo content >>file &&
120 git commit -a -m ten &&
121 GIT_REMOTE_TESTGIT_REFSPEC="" &&
122 export GIT_REMOTE_TESTGIT_REFSPEC &&
123 test_must_fail git push 2>../error) &&
124 grep "remote-helper doesn.t support push; refspec needed" error
127 test_expect_success 'pulling without marks' '
128 (cd local2 &&
129 GIT_REMOTE_TESTGIT_NO_MARKS=1 git pull) &&
130 compare_refs local2 HEAD server HEAD
133 test_expect_failure 'pushing without marks' '
134 test_when_finished "(cd local2 && git reset --hard origin)" &&
135 (cd local2 &&
136 echo content >>file &&
137 git commit -a -m twelve &&
138 GIT_REMOTE_TESTGIT_NO_MARKS=1 git push) &&
139 compare_refs local2 HEAD server HEAD
142 test_expect_success 'push all with existing object' '
143 (cd local &&
144 git branch dup2 master &&
145 git push origin --all
146 ) &&
147 compare_refs local dup2 server dup2
150 test_expect_success 'push ref with existing object' '
151 (cd local &&
152 git branch dup master &&
153 git push origin dup
154 ) &&
155 compare_refs local dup server dup
158 test_expect_success 'push update refs' '
159 (cd local &&
160 git checkout -b update master &&
161 echo update >>file &&
162 git commit -a -m update &&
163 git push origin update
164 git rev-parse --verify remotes/origin/update >expect &&
165 git rev-parse --verify testgit/origin/heads/update >actual &&
166 test_cmp expect actual
170 test_expect_success 'proper failure checks for fetching' '
171 (GIT_REMOTE_TESTGIT_FAILURE=1 &&
172 export GIT_REMOTE_TESTGIT_FAILURE &&
173 cd local &&
174 test_must_fail git fetch 2> error &&
175 cat error &&
176 grep -q "Error while running fast-import" error
180 test_expect_success 'proper failure checks for pushing' '
181 (GIT_REMOTE_TESTGIT_FAILURE=1 &&
182 export GIT_REMOTE_TESTGIT_FAILURE &&
183 cd local &&
184 test_must_fail git push --all 2> error &&
185 cat error &&
186 grep -q "Reading from helper .git-remote-testgit. failed" error
190 test_expect_success 'push messages' '
191 (cd local &&
192 git checkout -b new_branch master &&
193 echo new >>file &&
194 git commit -a -m new &&
195 git push origin new_branch &&
196 git fetch origin &&
197 echo new >>file &&
198 git commit -a -m new &&
199 git push origin new_branch 2> msg &&
200 ! grep "\[new branch\]" msg
204 test_done