diff --git a/Documentation/config.txt b/Documentation/config.txt index e75434b3ef2d81fa8dafd552d4b689eb84eea441..297101f1a560cb5601666098e94669e9cd4fbfa1 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -1623,7 +1623,9 @@ remote..tagopt:: Setting this value to \--no-tags disables automatic tag following when fetching from remote . Setting it to \--tags will fetch every tag from remote , even if they are not reachable from remote - branch heads. + branch heads. Passing these flags directly to linkgit:git-fetch[1] can + override this setting. See options \--tags and \--no-tags of + linkgit:git-fetch[1]. remote..vcs:: Setting this to a value will cause git to interact with diff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt index 9333c42c558464ce2430df39e9864f932e786b36..470ac31396606a18298f69329b050a86943c580c 100644 --- a/Documentation/fetch-options.txt +++ b/Documentation/fetch-options.txt @@ -49,7 +49,9 @@ ifndef::git-pull[] endif::git-pull[] By default, tags that point at objects that are downloaded from the remote repository are fetched and stored locally. - This option disables this automatic tag following. + This option disables this automatic tag following. The default + behavior for a remote may be specified with the remote..tagopt + setting. See linkgit:git-config[1]. -t:: --tags:: @@ -58,7 +60,9 @@ endif::git-pull[] objects reachable from the branch heads that are being tracked will not be fetched by this mechanism. This flag lets all tags and their associated objects be - downloaded. + downloaded. The default behavior for a remote may be + specified with the remote..tagopt setting. See + linkgit:git-config[1]. -u:: --update-head-ok:: diff --git a/builtin/fetch.c b/builtin/fetch.c index 6eb1dfea092e2873c5910bf4389d3b071786d8b0..42554680f74158051f290bdc613d7da72e07c173 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -675,10 +675,12 @@ static int do_fetch(struct transport *transport, for_each_ref(add_existing, &existing_refs); - if (transport->remote->fetch_tags == 2 && tags != TAGS_UNSET) - tags = TAGS_SET; - if (transport->remote->fetch_tags == -1) - tags = TAGS_UNSET; + if (tags == TAGS_DEFAULT) { + if (transport->remote->fetch_tags == 2) + tags = TAGS_SET; + if (transport->remote->fetch_tags == -1) + tags = TAGS_UNSET; + } if (!transport->get_refs_list || !transport->fetch) die("Don't know how to fetch from %s", transport->url); diff --git a/t/t5525-fetch-tagopt.sh b/t/t5525-fetch-tagopt.sh new file mode 100755 index 0000000000000000000000000000000000000000..4fbf7a120f3fd4133e09cb7cbe5c8e4597bfa27c --- /dev/null +++ b/t/t5525-fetch-tagopt.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +test_description='tagopt variable affects "git fetch" and is overridden by commandline.' + +. ./test-lib.sh + +setup_clone () { + git clone --mirror . $1 && + git remote add remote_$1 $1 && + (cd $1 && + git tag tag_$1) +} + +test_expect_success setup ' + test_commit test && + setup_clone one && + git config remote.remote_one.tagopt --no-tags && + setup_clone two && + git config remote.remote_two.tagopt --tags + ' + +test_expect_success "fetch with tagopt=--no-tags does not get tag" ' + git fetch remote_one && + test_must_fail git show-ref tag_one + ' + +test_expect_success "fetch --tags with tagopt=--no-tags gets tag" ' + git fetch --tags remote_one && + git show-ref tag_one + ' + +test_expect_success "fetch --no-tags with tagopt=--tags does not get tag" ' + git fetch --no-tags remote_two && + test_must_fail git show-ref tag_two + ' + +test_expect_success "fetch with tagopt=--tags gets tag" ' + git fetch remote_two && + git show-ref tag_two + ' +test_done