Skip to content

Commit ed36854

Browse files
ComputerDruidgitster
authored andcommitted
fetch: allow command line --tags to override config
Originally, if remote.<name>.tagopt was set, the --tags and option would have no effect when given to git fetch. So if tagopt="--no-tags" git fetch --tags would not actually fetch tags. This patch changes this behavior to only follow what is written in the config if there is no option passed by the command line. Signed-off-by: Daniel Johnson <ComputerDruid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 64fdc08 commit ed36854

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
@@ -1623,7 +1623,9 @@ remote.<name>.tagopt::
16231623
Setting this value to \--no-tags disables automatic tag following when
16241624
fetching from remote <name>. Setting it to \--tags will fetch every
16251625
tag from remote <name>, even if they are not reachable from remote
1626-
branch heads.
1626+
branch heads. Passing these flags directly to linkgit:git-fetch[1] can
1627+
override this setting. See options \--tags and \--no-tags of
1628+
linkgit:git-fetch[1].
16271629

16281630
remote.<name>.vcs::
16291631
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
@@ -675,10 +675,12 @@ static int do_fetch(struct transport *transport,
675675

676676
for_each_ref(add_existing, &existing_refs);
677677

678-
if (transport->remote->fetch_tags == 2 && tags != TAGS_UNSET)
679-
tags = TAGS_SET;
680-
if (transport->remote->fetch_tags == -1)
681-
tags = TAGS_UNSET;
678+
if (tags == TAGS_DEFAULT) {
679+
if (transport->remote->fetch_tags == 2)
680+
tags = TAGS_SET;
681+
if (transport->remote->fetch_tags == -1)
682+
tags = TAGS_UNSET;
683+
}
682684

683685
if (!transport->get_refs_list || !transport->fetch)
684686
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)