fetch: describe new refs based on where it came from
authorMarc Branchaud <marcnarc@xiplink.com>
Mon, 16 Apr 2012 22:08:50 +0000 (18:08 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 17 Apr 2012 15:26:00 +0000 (08:26 -0700)
update_local_ref() used to say "[new branch]" when we stored a new ref
outside refs/tags/ hierarchy, but the message is more about what we
fetched, so use the refname at the origin to make that decision.

Also, only call a new ref a "branch" if it's under refs/heads/.

Signed-off-by: Marc Branchaud <marcnarc@xiplink.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fetch.c
t/t5510-fetch.sh
index 06d71e4e4c795a96c4554c44178545b0f146e6a3..0f80cf81855fd8801de5a5f0548686fb19ab5068 100644 (file)
@@ -294,16 +294,24 @@ static int update_local_ref(struct ref *ref,
                const char *msg;
                const char *what;
                int r;
                const char *msg;
                const char *what;
                int r;
-               if (!strncmp(ref->name, "refs/tags/", 10)) {
+               /*
+                * Nicely describe the new ref we're fetching.
+                * Base this on the remote's ref name, as it's
+                * more likely to follow a standard layout.
+                */
+               const char *name = remote_ref ? remote_ref->name : "";
+               if (!prefixcmp(name, "refs/tags/")) {
                        msg = "storing tag";
                        what = _("[new tag]");
                        msg = "storing tag";
                        what = _("[new tag]");
-               }
-               else {
+               } else if (!prefixcmp(name, "refs/heads/")) {
                        msg = "storing head";
                        what = _("[new branch]");
                        if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
                            (recurse_submodules != RECURSE_SUBMODULES_ON))
                                check_for_new_submodule_commits(ref->new_sha1);
                        msg = "storing head";
                        what = _("[new branch]");
                        if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
                            (recurse_submodules != RECURSE_SUBMODULES_ON))
                                check_for_new_submodule_commits(ref->new_sha1);
+               } else {
+                       msg = "storing ref";
+                       what = _("[new ref]");
                }
 
                r = s_update_ref(msg, ref, 0);
                }
 
                r = s_update_ref(msg, ref, 0);
index 308c02ea75f3400b4d215e6091f03179a93943ad..d7a19a182941c7ab54b81bb8013835cfb8c5919f 100755 (executable)
@@ -162,6 +162,36 @@ test_expect_success 'fetch following tags' '
 
 '
 
 
 '
 
+test_expect_success 'fetch uses remote ref names to describe new refs' '
+       cd "$D" &&
+       git init descriptive &&
+       (
+               cd descriptive &&
+               git config remote.o.url .. &&
+               git config remote.o.fetch "refs/heads/*:refs/crazyheads/*" &&
+               git config --add remote.o.fetch "refs/others/*:refs/heads/*" &&
+               git fetch o
+       ) &&
+       git tag -a -m "Descriptive tag" descriptive-tag &&
+       git branch descriptive-branch &&
+       git checkout descriptive-branch &&
+       echo "Nuts" >crazy &&
+       git add crazy &&
+       git commit -a -m "descriptive commit" &&
+       git update-ref refs/others/crazy HEAD &&
+       (
+               cd descriptive &&
+               git fetch o 2>actual &&
+               grep " -> refs/crazyheads/descriptive-branch$" actual |
+               test_i18ngrep "new branch" &&
+               grep " -> descriptive-tag$" actual |
+               test_i18ngrep "new tag" &&
+               grep " -> crazy$" actual |
+               test_i18ngrep "new ref"
+       ) &&
+       git checkout master
+'
+
 test_expect_success 'fetch must not resolve short tag name' '
 
        cd "$D" &&
 test_expect_success 'fetch must not resolve short tag name' '
 
        cd "$D" &&