@matheusbsbs / matheus-bagliano / commits / ed36854651
Fork 0

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>

Daniel Johnson committed Aug 11, 2010 at 18:57 UTC ed36854651303dd18156786fc096de611f43912c
4 files changed +56 -7
Documentation/config.txt
+3 -1
@@ -1623,7 +1623,9 @@ remote.<name>.tagopt::
1623 Setting this value to \--no-tags disables automatic tag following when
1624 fetching from remote <name>. Setting it to \--tags will fetch every
1625 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].
1629
1630 remote.<name>.vcs::
1631 Setting this to a value <vcs> will cause git to interact with
Documentation/fetch-options.txt
+6 -2
@@ -49,7 +49,9 @@ ifndef::git-pull[]
49 endif::git-pull[]
50 By default, tags that point at objects that are downloaded
51 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].
55
56 -t::
57 --tags::
@@ -58,7 +60,9 @@ endif::git-pull[]
60 objects reachable from the branch heads that are being
61 tracked will not be fetched by this mechanism. This
62 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].
66
67 -u::
68 --update-head-ok::
builtin/fetch.c
+6 -4
@@ -675,10 +675,12 @@ static int do_fetch(struct transport *transport,
675
676 for_each_ref(add_existing, &existing_refs);
677
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 + }
684
685 if (!transport->get_refs_list || !transport->fetch)
686 die("Don't know how to fetch from %s", transport->url);
t/t5525-fetch-tagopt.sh new
+41
@@ -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