3 # Copyright (c) 2010 Sverre Rabbelier
6 test_description
='Test remote-helper import and export commands'
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' '
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' '
31 echo content >>file &&
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' '
42 echo content >>file &&
43 git commit -a -m three &&
45 compare_refs local HEAD server HEAD
48 test_expect_success
'fetch new branch' '
51 git checkout -b new &&
52 echo content >>file &&
58 compare_refs server HEAD local FETCH_HEAD
61 test_expect_success
'fetch multiple branches' '
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' '
71 git reset --hard origin/master &&
72 echo content >>file &&
73 git commit -a -m six &&
76 compare_refs local master server master
79 test_expect_success
'push new branch by name' '
81 git checkout -b new-name &&
82 echo content >>file &&
83 git commit -a -m seven &&
84 git push origin new-name
86 compare_refs local HEAD server refs/heads/new-name
89 test_expect_failure
'push new branch with old:new refspec' '
91 git push origin new-name:new-refspec
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' '
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)" &&
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' '
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)" &&
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' '
139 git branch dup2 master &&
140 git push origin --all
142 compare_refs local dup2 server dup2
145 test_expect_success
'push ref with existing object' '
147 git branch dup master &&
150 compare_refs local dup server dup
153 test_expect_success
'push update refs' '
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 &&
169 test_must_fail git fetch 2> 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 &&
179 test_must_fail git push --all 2> error &&
181 grep -q "Reading from helper .git-remote-testgit. failed" error
185 test_expect_success
'push messages' '
187 git checkout -b new_branch master &&
189 git commit -a -m new &&
190 git push origin new_branch &&
193 git commit -a -m new &&
194 git push origin new_branch 2> msg &&
195 ! grep "\[new branch\]" msg