Skip to content

Commit 8834fd4

Browse files
committed
Merge branch 'js/set-head-symref-fix' into seen
* js/set-head-symref-fix: Fix `git fetch --tags` in repo with no configured remote
2 parents 4a314e7 + f568b12 commit 8834fd4

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

builtin/fetch.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,15 +1753,14 @@ static int do_fetch(struct transport *transport,
17531753
}
17541754
}
17551755

1756+
strvec_push(&transport_ls_refs_options.ref_prefixes, "HEAD");
1757+
17561758
if (tags == TAGS_SET || tags == TAGS_DEFAULT) {
17571759
must_list_refs = 1;
1758-
if (transport_ls_refs_options.ref_prefixes.nr)
1759-
strvec_push(&transport_ls_refs_options.ref_prefixes,
1760-
"refs/tags/");
1760+
strvec_push(&transport_ls_refs_options.ref_prefixes,
1761+
"refs/tags/");
17611762
}
17621763

1763-
strvec_push(&transport_ls_refs_options.ref_prefixes, "HEAD");
1764-
17651764
if (must_list_refs) {
17661765
trace2_region_enter("fetch", "remote_refs", the_repository);
17671766
remote_refs = transport_get_remote_refs(transport,

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)