Skip to content

Commit 8a90ddd

Browse files
committed
Merge branch 'mb/fetch-call-a-non-branch-a-ref'
The report from "git fetch" said "new branch" even for a non branch ref. By Marc Branchaud * mb/fetch-call-a-non-branch-a-ref: fetch: describe new refs based on where it came from fetch: Give remote_ref to update_local_ref() as well
2 parents 653787a + 0997ada commit 8a90ddd

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

builtin/fetch.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ static int s_update_ref(const char *action,
240240

241241
static int update_local_ref(struct ref *ref,
242242
const char *remote,
243+
const struct ref *remote_ref,
243244
struct strbuf *display)
244245
{
245246
struct commit *current = NULL, *updated;
@@ -293,13 +294,21 @@ static int update_local_ref(struct ref *ref,
293294
const char *msg;
294295
const char *what;
295296
int r;
296-
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/")) {
297304
msg = "storing tag";
298305
what = _("[new tag]");
299-
}
300-
else {
306+
} else if (!prefixcmp(name, "refs/heads/")) {
301307
msg = "storing head";
302308
what = _("[new branch]");
309+
} else {
310+
msg = "storing ref";
311+
what = _("[new ref]");
303312
}
304313

305314
if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
@@ -466,7 +475,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
466475

467476
strbuf_reset(&note);
468477
if (ref) {
469-
rc |= update_local_ref(ref, what, &note);
478+
rc |= update_local_ref(ref, what, rm, &note);
470479
free(ref);
471480
} else
472481
strbuf_addf(&note, "* %-*s %-*s -> FETCH_HEAD",

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)