Skip to content

Commit 0997ada

Browse files
marcnarcgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6da618d commit 0997ada

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

builtin/fetch.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,16 +294,24 @@ static int update_local_ref(struct ref *ref,
294294
const char *msg;
295295
const char *what;
296296
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/")) {
298304
msg = "storing tag";
299305
what = _("[new tag]");
300-
}
301-
else {
306+
} else if (!prefixcmp(name, "refs/heads/")) {
302307
msg = "storing head";
303308
what = _("[new branch]");
304309
if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
305310
(recurse_submodules != RECURSE_SUBMODULES_ON))
306311
check_for_new_submodule_commits(ref->new_sha1);
312+
} else {
313+
msg = "storing ref";
314+
what = _("[new ref]");
307315
}
308316

309317
r = s_update_ref(msg, ref, 0);

t/t5510-fetch.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,36 @@ test_expect_success 'fetch following tags' '
162162
163163
'
164164

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+
165195
test_expect_success 'fetch must not resolve short tag name' '
166196
167197
cd "$D" &&

0 commit comments

Comments
 (0)