Skip to content

Commit 7358320

Browse files
committed
Merge branch 'nk/refspecs-negative-fix'
Hotfix for recent regression. * nk/refspecs-negative-fix: negative-refspec: improve comment on query_matches_negative_refspec negative-refspec: fix segfault on : refspec
2 parents 7a50265 + 773c694 commit 7358320

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

remote.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,12 @@ static int query_matches_negative_refspec(struct refspec *rs, struct refspec_ite
736736
* item uses the destination. To handle this, we apply pattern
737737
* refspecs in reverse to figure out if the query source matches any
738738
* of the negative refspecs.
739+
*
740+
* The first loop finds and expands all positive refspecs
741+
* matched by the queried ref.
742+
*
743+
* The second loop checks if any of the results of the first loop
744+
* match any negative refspec.
739745
*/
740746
for (i = 0; i < rs->nr; i++) {
741747
struct refspec_item *refspec = &rs->items[i];
@@ -751,9 +757,13 @@ static int query_matches_negative_refspec(struct refspec *rs, struct refspec_ite
751757

752758
if (match_name_with_pattern(key, needle, value, &expn_name))
753759
string_list_append_nodup(&reversed, expn_name);
754-
} else {
755-
if (!strcmp(needle, refspec->src))
756-
string_list_append(&reversed, refspec->src);
760+
} else if (refspec->matching) {
761+
/* For the special matching refspec, any query should match */
762+
string_list_append(&reversed, needle);
763+
} else if (!refspec->src) {
764+
BUG("refspec->src should not be null here");
765+
} else if (!strcmp(needle, refspec->src)) {
766+
string_list_append(&reversed, refspec->src);
757767
}
758768
}
759769

t/t5582-fetch-negative-refspec.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
189240
test_done

0 commit comments

Comments
 (0)