Skip to content

Commit 5c07c15

Browse files
committed
Merge branch 'js/set-head-symref-fix' into seen
The implicit set-HEAD feature being added to "git fetch" breaks "git fetch --tags $there" that does not use any remore-tracking hierarchy, which has been corrected. * js/set-head-symref-fix: fetch: do not ask for HEAD unnecessarily
2 parents 5142340 + 7d55df6 commit 5c07c15

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

builtin/fetch.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,21 @@ static int set_head(const struct ref *remote_refs, int follow_remote_head,
16911691
return result;
16921692
}
16931693

1694+
static int uses_remote_tracking(struct transport *transport, struct refspec *rs)
1695+
{
1696+
if (!remote_is_configured(transport->remote, 0))
1697+
return 0;
1698+
1699+
if (!rs->nr)
1700+
rs = &transport->remote->fetch;
1701+
1702+
for (int i = 0; i < rs->nr; i++)
1703+
if (rs->items[i].dst)
1704+
return 1;
1705+
1706+
return 0;
1707+
}
1708+
16941709
static int do_fetch(struct transport *transport,
16951710
struct refspec *rs,
16961711
const struct fetch_config *config)
@@ -1760,7 +1775,10 @@ static int do_fetch(struct transport *transport,
17601775
"refs/tags/");
17611776
}
17621777

1763-
strvec_push(&transport_ls_refs_options.ref_prefixes, "HEAD");
1778+
if (uses_remote_tracking(transport, rs)) {
1779+
must_list_refs = 1;
1780+
strvec_push(&transport_ls_refs_options.ref_prefixes, "HEAD");
1781+
}
17641782

17651783
if (must_list_refs) {
17661784
trace2_region_enter("fetch", "remote_refs", the_repository);

t/t5510-fetch.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,23 @@ test_expect_success 'fetch --prune --tags with refspec prunes based on refspec'
326326
git rev-parse sometag
327327
'
328328

329+
test_expect_success 'fetch --tags gets tags even without a configured remote' '
330+
REMOTE="$(pwd)/test_tag_1" &&
331+
git init test_tag_1 &&
332+
(
333+
cd test_tag_1 &&
334+
test_commit foo
335+
) &&
336+
git init test_tag_2 &&
337+
(
338+
cd test_tag_2 &&
339+
git fetch --tags "file://$REMOTE" &&
340+
echo "foo" >expect &&
341+
git tag >actual &&
342+
test_cmp expect actual
343+
)
344+
'
345+
329346
test_expect_success REFFILES 'fetch --prune fails to delete branches' '
330347
cd "$D" &&
331348
git clone . prune-fail &&

0 commit comments

Comments
 (0)