Skip to content

Commit 1ed10b8

Browse files
committed
remote.c: "git-push frotz" should update what matches at the source.
Earlier, when the local repository has a branch "frotz" and the remote repository has a tag "frotz" (but not branch "frotz"), "git-push frotz" mistakenly updated the tag at the remote side. This was because the partial refname matching code was applied independently on both source and destination side. With this fix, when a colon-less refspec is given to git-push, we first match it with the refs in the source repository, and update the matching ref in the destination repository. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 6125796 commit 1ed10b8

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
lines changed

remote.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -455,19 +455,14 @@ static int match_explicit(struct ref *src, struct ref *dst,
455455
errs = 1;
456456

457457
if (dst_value == NULL)
458-
dst_value = rs->src;
458+
dst_value = matched_src->name;
459459

460460
switch (count_refspec_match(dst_value, dst, &matched_dst)) {
461461
case 1:
462462
break;
463463
case 0:
464464
if (!memcmp(dst_value, "refs/", 5))
465465
matched_dst = make_dst(dst_value, dst_tail);
466-
else if (!strcmp(rs->src, dst_value) && matched_src)
467-
/* pushing "master:master" when
468-
* remote does not have master yet.
469-
*/
470-
matched_dst = make_dst(matched_src->name, dst_tail);
471466
else
472467
error("dst refspec %s does not match any "
473468
"existing ref on the remote and does "

t/t5516-fetch-push.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,58 @@ test_expect_success 'push with ambiguity (2)' '
189189
else
190190
check_push_result $the_first_commit heads/frotz tags/frotz
191191
fi
192+
193+
'
194+
195+
test_expect_success 'push with colon-less refspec (1)' '
196+
197+
mk_test heads/frotz tags/frotz &&
198+
git branch -f frotz master &&
199+
git push testrepo frotz &&
200+
check_push_result $the_commit heads/frotz &&
201+
check_push_result $the_first_commit tags/frotz
202+
203+
'
204+
205+
test_expect_success 'push with colon-less refspec (2)' '
206+
207+
mk_test heads/frotz tags/frotz &&
208+
if git show-ref --verify -q refs/heads/frotz
209+
then
210+
git branch -D frotz
211+
fi &&
212+
git tag -f frotz &&
213+
git push testrepo frotz &&
214+
check_push_result $the_commit tags/frotz &&
215+
check_push_result $the_first_commit heads/frotz
216+
217+
'
218+
219+
test_expect_success 'push with colon-less refspec (3)' '
220+
221+
mk_test &&
222+
if git show-ref --verify -q refs/tags/frotz
223+
then
224+
git tag -d frotz
225+
fi &&
226+
git branch -f frotz master &&
227+
git push testrepo frotz &&
228+
check_push_result $the_commit heads/frotz &&
229+
test "$( cd testrepo && git show-ref | wc -l )" = 1
230+
'
231+
232+
test_expect_success 'push with colon-less refspec (4)' '
233+
234+
mk_test &&
235+
if git show-ref --verify -q refs/heads/frotz
236+
then
237+
git branch -D frotz
238+
fi &&
239+
git tag -f frotz &&
240+
git push testrepo frotz &&
241+
check_push_result $the_commit tags/frotz &&
242+
test "$( cd testrepo && git show-ref | wc -l )" = 1
243+
192244
'
193245

194246
test_done

0 commit comments

Comments
 (0)