Subject: Re: [PATCH] Make git-clone --use-separate-remote the default

From: Salikh Zakirov <[email-masked]>
Date: Sat, 25 Nov 2006 02:28:02 +0300

Junio C Hamano wrote:
> The way this command:
> 
> 	git push $remote $src:$dst
> 
> is handled is:
> 
>  (0) send-pack gets ls-remote equivalent from the remote.  This
>      tells us the set of refs the remote has and the value of
>      each of them.
> 
>  (1) $src can be a ref that is resolved locally the usual way.
>      You could have any valid SHA-1 expression (e.g. HEAD~6).

>  (2) $dst is compared with the list of refs that the remote
>      has, and unique match is found.

I think that remote matching semantics is confusing, and the following change
would make understanding easier.

I was understanding the manual incorrectly for a long time until you've
explained its true meaning today (thanks!).

As a side effect, making 'git push repo master' unambiguously expanded
to 'git push repo refs/heads/master:refs/heads/master' will make
the syntax 'git push repo tag v1' unneeded at all, because it would be
exactly the same as 'git push repo v1'
(expanded to 'git push repo refs/tags/v1:refs/tags/v1').

--- connect.c
+++ connect.c
@@ -277,6 +277,16 @@ static int match_explicit_refs(struct re
                              rs[i].src);
                        break;
                }
+               if (!strcmp(rs[i].src,rs[i].dst)) {
+                       /* src refspec is the same as dst,
+                        * take the remote refpath exactly the same
+                        * as existing local reference
+                        */
+                       int len = strlen(matched_src->name) + 1;
+                       matched_dst = xcalloc(1, sizeof(*dst) + len);
+                       memcpy(matched_dst->name, matched_src->name, len);
+                       link_dst_tail(matched_dst, dst_tail);
+               } else
                switch (count_refspec_match(rs[i].dst, dst, &matched_dst)) {
                case 1:
                        break;