3 test_description
='pushing to a repository using the atomic push option'
8 rm -rf workbench upstream
&&
9 test_create_repo upstream
&&
10 test_create_repo workbench
&&
13 git config receive.denyCurrentBranch warn
17 git remote add up ..
/upstream
21 # Compare the ref ($1) in upstream with a ref value from workbench ($2)
22 # i.e. test_refs second HEAD@{2}
25 git
-C upstream rev-parse
--verify "$1" >expect
&&
26 git
-C workbench rev-parse
--verify "$2" >actual
&&
27 test_cmp expect actual
30 fmt_status_report
() {
32 -e "/^To / { s/ */ /g; p; }" \
33 -e "/^ ! / { s/ */ /g; p; }"
36 test_expect_success
'atomic push works for a single branch' '
41 git push --mirror up &&
43 git push --atomic up master
45 test_refs master master
48 test_expect_success
'atomic push works for two branches' '
54 git push --mirror up &&
56 git checkout second &&
58 git push --atomic up master second
60 test_refs master master &&
61 test_refs second second
64 test_expect_success
'atomic push works in combination with --mirror' '
69 git checkout -b second &&
71 git push --atomic --mirror up
73 test_refs master master &&
74 test_refs second second
77 test_expect_success
'atomic push works in combination with --force' '
82 git branch second master &&
84 git checkout second &&
86 test_commit three_b &&
88 git push --mirror up &&
89 # The actual test is below
90 git checkout master &&
91 test_commit three_a &&
92 git checkout second &&
93 git reset --hard HEAD^ &&
94 git push --force --atomic up master second
96 test_refs master master &&
97 test_refs second second
100 # set up two branches where master can be pushed but second can not
101 # (non-fast-forward). Since second can not be pushed the whole operation
102 # will fail and leave master untouched.
103 test_expect_success
'atomic push fails if one branch fails' '
108 git checkout -b second master &&
112 git push --mirror up &&
113 git reset --hard HEAD~2 &&
115 git checkout master &&
117 test_must_fail git push --atomic --all up
119 test_refs master HEAD@{7} &&
120 test_refs second HEAD@{4}
123 test_expect_success
'atomic push fails if one tag fails remotely' '
129 git checkout -b second master &&
133 # a third party modifies the server side:
136 git checkout second &&
137 git tag test_tag second
139 # see if we can now push both branches.
142 git checkout master &&
144 git checkout second &&
147 test_must_fail git push --tags --atomic up master second
149 test_refs master HEAD@{3} &&
150 test_refs second HEAD@{1}
153 test_expect_success
'atomic push obeys update hook preventing a branch to be pushed' '
158 git checkout -b second master &&
164 HOOKDIR="$(git rev-parse --git-dir)/hooks" &&
165 HOOK="$HOOKDIR/update" &&
166 mkdir -p "$HOOKDIR" &&
167 write_script "$HOOK" <<-\EOF
168 # only allow update to master from now on
169 test "$1" = "refs/heads/master"
174 git checkout master &&
176 git checkout second &&
178 test_must_fail git push --atomic up master second
180 test_refs master HEAD@{3} &&
181 test_refs second HEAD@{1}
184 test_expect_success
'atomic push is not advertised if configured' '
188 git config receive.advertiseatomic 0
193 git push --mirror up &&
195 test_must_fail git push --atomic up master
197 test_refs master HEAD@{1}
200 # References in upstream : master(1) one(1) foo(1)
201 # References in workbench: master(2) foo(1) two(2) bar(2)
202 # Atomic push : master(2) two(2) bar(2)
203 test_expect_success
'atomic push reports (reject by update hook)' '
209 git push up master one foo &&
213 mkdir -p upstream/.git/hooks &&
214 cat >upstream/.git/hooks/update <<-EOF &&
217 if test "\$1" = "refs/heads/bar"
219 echo >&2 "Pusing to branch bar is prohibited"
223 chmod a+x upstream/.git/hooks/update
230 test_must_fail git -C workbench \
231 push --atomic up master two bar >out 2>&1 &&
232 fmt_status_report <out >actual &&
233 cat >expect <<-EOF &&
235 ! [remote rejected] master -> master (atomic push failure)
236 ! [remote rejected] two -> two (atomic push failure)
237 ! [remote rejected] bar -> bar (hook declined)
239 test_cmp expect actual
242 # References in upstream : master(1) one(1) foo(1)
243 # References in workbench: master(2) foo(1) two(2) bar(2)
244 test_expect_success
'atomic push reports (mirror, but reject by update hook)' '
247 git remote remove up &&
248 git remote add up ../upstream
250 test_must_fail git -C workbench \
251 push --atomic --mirror up >out 2>&1 &&
252 fmt_status_report <out >actual &&
253 cat >expect <<-EOF &&
255 ! [remote rejected] master -> master (atomic push failure)
256 ! [remote rejected] one (atomic push failure)
257 ! [remote rejected] bar -> bar (hook declined)
258 ! [remote rejected] two -> two (atomic push failure)
260 test_cmp expect actual
263 # References in upstream : master(2) one(1) foo(1)
264 # References in workbench: master(1) foo(1) two(2) bar(2)
265 test_expect_success
'atomic push reports (reject by non-ff)' '
266 rm upstream/.git/hooks/update &&
269 git push up master &&
270 git reset --hard HEAD^
272 test_must_fail git -C workbench \
273 push --atomic up master foo bar >out 2>&1 &&
274 fmt_status_report <out >actual &&
275 cat >expect <<-EOF &&
277 ! [rejected] master -> master (non-fast-forward)
278 ! [rejected] bar -> bar (atomic push failed)
280 test_cmp expect actual