3 # Copyright (c) 2010 Sverre Rabbelier
6 test_description='Test remote-helper import and export commands'
10 if ! type "${BASH-bash}" >/dev/null 2>&1; then
11 skip_all='skipping remote-testgit tests, bash not available'
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' '
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' '
36 echo content >>file &&
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' '
47 echo content >>file &&
48 git commit -a -m three &&
50 compare_refs local HEAD server HEAD
53 test_expect_success 'fetch new branch' '
56 git checkout -b new &&
57 echo content >>file &&
63 compare_refs server HEAD local FETCH_HEAD
66 test_expect_success 'fetch multiple branches' '
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' '
76 git reset --hard origin/master &&
77 echo content >>file &&
78 git commit -a -m six &&
81 compare_refs local master server master
84 test_expect_success 'push new branch by name' '
86 git checkout -b new-name &&
87 echo content >>file &&
88 git commit -a -m seven &&
89 git push origin new-name
91 compare_refs local HEAD server refs/heads/new-name
94 test_expect_failure 'push new branch with old:new refspec' '
96 git push origin new-name:new-refspec
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' '
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)" &&
119 echo content >>file &&
120 git commit -a -m ten &&
121 GIT_REMOTE_TESTGIT_REFSPEC="" test_must_fail git push 2>../error) &&
122 grep "remote-helper doesn.t support push; refspec needed" error
125 test_expect_success 'pulling without marks' '
127 GIT_REMOTE_TESTGIT_NO_MARKS=1 git pull) &&
128 compare_refs local2 HEAD server HEAD
131 test_expect_failure 'pushing without marks' '
132 test_when_finished "(cd local2 && git reset --hard origin)" &&
134 echo content >>file &&
135 git commit -a -m twelve &&
136 GIT_REMOTE_TESTGIT_NO_MARKS=1 git push) &&
137 compare_refs local2 HEAD server HEAD
140 test_expect_success 'push all with existing object' '
142 git branch dup2 master &&
143 git push origin --all
145 compare_refs local dup2 server dup2
148 test_expect_success 'push ref with existing object' '
150 git branch dup master &&
153 compare_refs local dup server dup
156 test_expect_success 'push update refs' '
158 git checkout -b update master &&
159 echo update >>file &&
160 git commit -a -m update &&
161 git push origin update
162 git rev-parse --verify remotes/origin/update >expect &&
163 git rev-parse --verify testgit/origin/heads/update >actual &&
164 test_cmp expect actual
168 test_expect_success 'proper failure checks for fetching' '
169 (GIT_REMOTE_TESTGIT_FAILURE=1 &&
170 export GIT_REMOTE_TESTGIT_FAILURE &&
172 test_must_fail git fetch 2> error &&
174 grep -q "Error while running fast-import" error
178 test_expect_success 'proper failure checks for pushing' '
179 (GIT_REMOTE_TESTGIT_FAILURE=1 &&
180 export GIT_REMOTE_TESTGIT_FAILURE &&
182 test_must_fail git push --all 2> error &&
184 grep -q "Reading from helper .git-remote-testgit. failed" error
188 test_expect_success 'push messages' '
190 git checkout -b new_branch master &&
192 git commit -a -m new &&
193 git push origin new_branch &&
196 git commit -a -m new &&
197 git push origin new_branch 2> msg &&
198 ! grep "\[new branch\]" msg