fetch: describe new refs based on where it came from

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>

Marc Branchaud committed Apr 16, 2012 at 18:08 UTC 0997adaa74dfe07cee3180c3a6fd91949fb4e3d8
2 files changed +41 -3
builtin/fetch.c
+11 -3
@@ -294,16 +294,24 @@ static int update_local_ref(struct ref *ref,
294 const char *msg;
295 const char *what;
296 int r;
297 - if (!strncmp(ref->name, "refs/tags/", 10)) {
297 + /*
298 + * Nicely describe the new ref we're fetching.
299 + * Base this on the remote's ref name, as it's
300 + * more likely to follow a standard layout.
301 + */
302 + const char *name = remote_ref ? remote_ref->name : "";
303 + if (!prefixcmp(name, "refs/tags/")) {
304 msg = "storing tag";
305 what = _("[new tag]");
300 - }
301 - else {
306 + } else if (!prefixcmp(name, "refs/heads/")) {
307 msg = "storing head";
308 what = _("[new branch]");
309 if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
310 (recurse_submodules != RECURSE_SUBMODULES_ON))
311 check_for_new_submodule_commits(ref->new_sha1);
312 + } else {
313 + msg = "storing ref";
314 + what = _("[new ref]");
315 }
316
317 r = s_update_ref(msg, ref, 0);
t/t5510-fetch.sh
+30
@@ -162,6 +162,36 @@ test_expect_success 'fetch following tags' '
162
163 '
164
165 +test_expect_success 'fetch uses remote ref names to describe new refs' '
166 + cd "$D" &&
167 + git init descriptive &&
168 + (
169 + cd descriptive &&
170 + git config remote.o.url .. &&
171 + git config remote.o.fetch "refs/heads/*:refs/crazyheads/*" &&
172 + git config --add remote.o.fetch "refs/others/*:refs/heads/*" &&
173 + git fetch o
174 + ) &&
175 + git tag -a -m "Descriptive tag" descriptive-tag &&
176 + git branch descriptive-branch &&
177 + git checkout descriptive-branch &&
178 + echo "Nuts" >crazy &&
179 + git add crazy &&
180 + git commit -a -m "descriptive commit" &&
181 + git update-ref refs/others/crazy HEAD &&
182 + (
183 + cd descriptive &&
184 + git fetch o 2>actual &&
185 + grep " -> refs/crazyheads/descriptive-branch$" actual |
186 + test_i18ngrep "new branch" &&
187 + grep " -> descriptive-tag$" actual |
188 + test_i18ngrep "new tag" &&
189 + grep " -> crazy$" actual |
190 + test_i18ngrep "new ref"
191 + ) &&
192 + git checkout master
193 +'
194 +
195 test_expect_success 'fetch must not resolve short tag name' '
196
197 cd "$D" &&