177
test $HEAD = $(git rev-parse --verify HEAD))
178
'
179
180
+test_expect_success 'push --atomic also prevents branch creation, reports collateral' '
181
+ # Setup upstream repo - empty for now
182
+ d=$HTTPD_DOCUMENT_ROOT_PATH/atomic-branches.git &&
183
+ git init --bare "$d" &&
184
+ test_config -C "$d" http.receivepack true &&
185
+ up="$HTTPD_URL"/smart/atomic-branches.git &&
186
+
187
+ # Tell "$up" about two branches for now
188
+ test_commit atomic1 &&
189
+ test_commit atomic2 &&
190
+ git branch collateral &&
191
+ git push "$up" master collateral &&
192
+
193
+ # collateral is a valid push, but should be failed by atomic push
194
+ git checkout collateral &&
195
+ test_commit collateral1 &&
196
+
197
+ # Make master incompatible with upstream to provoke atomic
198
+ git checkout master &&
199
+ git reset --hard HEAD^ &&
200
+
201
+ # Add a new branch which should be failed by atomic push. This is a
202
+ # regression case.
203
+ git branch atomic &&
204
+
205
+ # --atomic should cause entire push to be rejected
206
+ test_must_fail git push --atomic "$up" master atomic collateral 2>output &&
207
+
208
+ # the new branch should not have been created upstream
209
+ test_must_fail git -C "$d" show-ref --verify refs/heads/atomic &&
210
+
211
+ # upstream should still reflect atomic2, the last thing we pushed
212
+ # successfully
213
+ git rev-parse atomic2 >expected &&
214
+ # on master...
215
+ git -C "$d" rev-parse refs/heads/master >actual &&
216
+ test_cmp expected actual &&
217
+ # ...and collateral.
218
+ git -C "$d" rev-parse refs/heads/collateral >actual &&
219
+ test_cmp expected actual &&
220
+
221
+ # the failed refs should be indicated to the user
222
+ grep "^ ! .*rejected.* master -> master" output &&
223
+
224
+ # the collateral failure refs should be indicated to the user
225
+ grep "^ ! .*rejected.* atomic -> atomic .*atomic push failed" output &&
226
+ grep "^ ! .*rejected.* collateral -> collateral .*atomic push failed" output
227
+'
228
+
229
test_expect_success 'push --all can push to empty repo' '
230
d=$HTTPD_DOCUMENT_ROOT_PATH/empty-all.git &&
231
git init --bare "$d" &&