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>
Junio C Hamano committed
Jun 9, 2007 at 01:37 UTC
1ed10b886bc69c129c06772ee4310c00e001657f
2 files changed
+53
-6
remote.c
+1
-6
@@ -455,7 +455,7 @@ static int match_explicit(struct ref *src, struct ref *dst,
455
errs = 1;
456
457
if (dst_value == NULL)
458
- dst_value = rs->src;
458
+ dst_value = matched_src->name;
459
460
switch (count_refspec_match(dst_value, dst, &matched_dst)) {
461
case 1:
@@ -463,11 +463,6 @@ static int match_explicit(struct ref *src, struct ref *dst,
463
case 0:
464
if (!memcmp(dst_value, "refs/", 5))
465
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);
466
else
467
error("dst refspec %s does not match any "
468
"existing ref on the remote and does "
t/t5516-fetch-push.sh
+52
@@ -189,6 +189,58 @@ test_expect_success 'push with ambiguity (2)' '
189
else
190
check_push_result $the_first_commit heads/frotz tags/frotz
191
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
+
244
'
245
246
test_done