Skip to content

Commit 381b2e7

Browse files
committed
Merge branch 'dj/fetch-tagopt'
* dj/fetch-tagopt: fetch: allow command line --tags to override config
2 parents 3f29dd6 + ed36854 commit 381b2e7

4 files changed

Lines changed: 56 additions & 7 deletions

File tree

Documentation/config.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,9 @@ remote.<name>.tagopt::
16461646
Setting this value to \--no-tags disables automatic tag following when
16471647
fetching from remote <name>. Setting it to \--tags will fetch every
16481648
tag from remote <name>, even if they are not reachable from remote
1649-
branch heads.
1649+
branch heads. Passing these flags directly to linkgit:git-fetch[1] can
1650+
override this setting. See options \--tags and \--no-tags of
1651+
linkgit:git-fetch[1].
16501652

16511653
remote.<name>.vcs::
16521654
Setting this to a value <vcs> will cause git to interact with

Documentation/fetch-options.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ ifndef::git-pull[]
4949
endif::git-pull[]
5050
By default, tags that point at objects that are downloaded
5151
from the remote repository are fetched and stored locally.
52-
This option disables this automatic tag following.
52+
This option disables this automatic tag following. The default
53+
behavior for a remote may be specified with the remote.<name>.tagopt
54+
setting. See linkgit:git-config[1].
5355

5456
-t::
5557
--tags::
@@ -58,7 +60,9 @@ endif::git-pull[]
5860
objects reachable from the branch heads that are being
5961
tracked will not be fetched by this mechanism. This
6062
flag lets all tags and their associated objects be
61-
downloaded.
63+
downloaded. The default behavior for a remote may be
64+
specified with the remote.<name>.tagopt setting. See
65+
linkgit:git-config[1].
6266

6367
-u::
6468
--update-head-ok::

builtin/fetch.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,10 +659,12 @@ static int do_fetch(struct transport *transport,
659659

660660
for_each_ref(add_existing, &existing_refs);
661661

662-
if (transport->remote->fetch_tags == 2 && tags != TAGS_UNSET)
663-
tags = TAGS_SET;
664-
if (transport->remote->fetch_tags == -1)
665-
tags = TAGS_UNSET;
662+
if (tags == TAGS_DEFAULT) {
663+
if (transport->remote->fetch_tags == 2)
664+
tags = TAGS_SET;
665+
if (transport->remote->fetch_tags == -1)
666+
tags = TAGS_UNSET;
667+
}
666668

667669
if (!transport->get_refs_list || !transport->fetch)
668670
die("Don't know how to fetch from %s", transport->url);

t/t5525-fetch-tagopt.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/sh
2+
3+
test_description='tagopt variable affects "git fetch" and is overridden by commandline.'
4+
5+
. ./test-lib.sh
6+
7+
setup_clone () {
8+
git clone --mirror . $1 &&
9+
git remote add remote_$1 $1 &&
10+
(cd $1 &&
11+
git tag tag_$1)
12+
}
13+
14+
test_expect_success setup '
15+
test_commit test &&
16+
setup_clone one &&
17+
git config remote.remote_one.tagopt --no-tags &&
18+
setup_clone two &&
19+
git config remote.remote_two.tagopt --tags
20+
'
21+
22+
test_expect_success "fetch with tagopt=--no-tags does not get tag" '
23+
git fetch remote_one &&
24+
test_must_fail git show-ref tag_one
25+
'
26+
27+
test_expect_success "fetch --tags with tagopt=--no-tags gets tag" '
28+
git fetch --tags remote_one &&
29+
git show-ref tag_one
30+
'
31+
32+
test_expect_success "fetch --no-tags with tagopt=--tags does not get tag" '
33+
git fetch --no-tags remote_two &&
34+
test_must_fail git show-ref tag_two
35+
'
36+
37+
test_expect_success "fetch with tagopt=--tags gets tag" '
38+
git fetch remote_two &&
39+
git show-ref tag_two
40+
'
41+
test_done

0 commit comments

Comments
 (0)