@@ -186,4 +186,55 @@ test_expect_success "fetch --prune with negative refspec" '
186186)
187187'
188188
189+ test_expect_success " push with matching : and negative refspec" '
190+ # Manually handle cleanup, since test_config is not
191+ # prepared to take arbitrary options like --add
192+ test_when_finished "test_unconfig -C two remote.one.push" &&
193+
194+ # For convenience, we use "master" to refer to the name of
195+ # the branch created by default in the following.
196+ #
197+ # Repositories two and one have branches other than "master"
198+ # but they have no overlap---"master" is the only one that
199+ # is shared between them. And the master branch at two is
200+ # behind the master branch at one by one commit.
201+ git -C two config --add remote.one.push : &&
202+
203+ # A matching push tries to update master, fails due to non-ff
204+ test_must_fail git -C two push one &&
205+
206+ # "master" may actually not be "master"---find it out.
207+ current=$(git symbolic-ref HEAD) &&
208+
209+ # If master is in negative refspec, then the command will not attempt
210+ # to push and succeed.
211+ git -C two config --add remote.one.push "^$current" &&
212+
213+ # With "master" excluded, this push is a no-op. Nothing gets
214+ # pushed and it succeeds.
215+ git -C two push -v one
216+ '
217+
218+ test_expect_success " push with matching +: and negative refspec" '
219+ test_when_finished "test_unconfig -C two remote.one.push" &&
220+
221+ # The same set-up as above, whose side-effect was a no-op.
222+ git -C two config --add remote.one.push +: &&
223+
224+ # The push refuses to update the "master" branch that is checked
225+ # out in the "one" repository, even when it is forced with +:
226+ test_must_fail git -C two push one &&
227+
228+ # "master" may actually not be "master"---find it out.
229+ current=$(git symbolic-ref HEAD) &&
230+
231+ # If master is in negative refspec, then the command will not attempt
232+ # to push and succeed
233+ git -C two config --add remote.one.push "^$current" &&
234+
235+ # With "master" excluded, this push is a no-op. Nothing gets
236+ # pushed and it succeeds.
237+ git -C two push -v one
238+ '
239+
189240test_done
0 commit comments