{"thread":{"id":"58607","subject":"[BUG] git fetch fetches tags matching negative refspec","startedAt":"2022-10-12T08:30:06Z","lastAt":"2022-10-18T12:41:30Z","messageCount":7,"participants":["Erik Cervin Edin","Ævar Arnfjörð Bjarmason","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"464655","messageId":"CA+JQ7M-CN0UnHQDDDVz0kPcU1AcoL9+WFOeR8eiw_B=Yiyc-CA@mail.gmail.com","threadId":"58607","inReplyTo":null,"subject":"[BUG] git fetch fetches tags matching negative refspec","fromName":"Erik Cervin Edin","fromEmail":"erik@cervined.in","sentAt":"2022-10-12T08:29:20Z","receivedAt":"2022-10-12T08:30:06Z","isPatch":false,"sender":{"key":"erik@cervined.in","avatar":null},"body":"Thank you for filling out a Git bug report!\nPlease answer the following questions to help us understand your issue.\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\n\nDelete all v2.9.* tags\n  git tag | grep ^v2.9.* | xargs git tag -d\n\nChange standard the standard fetch configuration\n[remote \"origin\"]\n    url = git@github.com:git/git.git\n    fetch = +refs/heads/*:refs/remotes/origin/*\n\nBy adding a negative respec for tags matching v2.9.*\n[remote \"origin\"]\n    url = git@github.com:git/git.git\n    fetch = +refs/heads/*:refs/remotes/origin/*\n    fetch = ^refs/tags/v2.9.*\n\nrun\n  git fetch\n\nWhat did you expect to happen? (Expected behavior)\n\nTo exclude tags matchings v2.9*, just like when running git fetch --tags\n\nWhat happened instead? (Actual behavior)\n\nWithout specifying git fetch --tags, tags matching the negative\nrefspec are still fetched\n\nWhat's different between what you expected and what actually happened?\n\nThe negative refspec appears to be ignored or overruled when running\ngit fetch without the --tags flag\n\nAnything else you want to add:\nI love git, thank you! ♥\n\nPlease review the rest of the bug report below.\nYou can delete any lines you don't wish to share.\n\n\n[System Info]\ngit version:\ngit version 2.38.0.windows.1\ncpu: x86_64\nbuilt from commit: 0355083fbe5582f6d3f819afc130ed2f2375e0bd\nsizeof-long: 4\nsizeof-size_t: 8\nshell-path: /bin/sh\nfeature: fsmonitor--daemon\nuname: Windows 10.0 19044\ncompiler info: gnuc: 12.2\nlibc info: no libc information available\n$SHELL (typically, interactive shell): C:\\Users\\erik\\Git\\usr\\bin\\bash.exe\n\n\n[Enabled Hooks]\n"},{"id":"464683","messageId":"221012.86mta1mmli.gmgdl@evledraar.gmail.com","threadId":"58607","inReplyTo":"CA+JQ7M-CN0UnHQDDDVz0kPcU1AcoL9+WFOeR8eiw_B=Yiyc-CA@mail.gmail.com","subject":"Re: [BUG] git fetch fetches tags matching negative refspec","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-12T09:11:47Z","receivedAt":"2022-10-12T09:13:03Z","isPatch":false,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Wed, Oct 12 2022, Erik Cervin Edin wrote:\n\n> Thank you for filling out a Git bug report!\n> Please answer the following questions to help us understand your issue.\n>\n> What did you do before the bug happened? (Steps to reproduce your issue)\n>\n> Delete all v2.9.* tags\n>   git tag | grep ^v2.9.* | xargs git tag -d\n>\n> Change standard the standard fetch configuration\n> [remote \"origin\"]\n>     url = git@github.com:git/git.git\n>     fetch = +refs/heads/*:refs/remotes/origin/*\n>\n> By adding a negative respec for tags matching v2.9.*\n> [remote \"origin\"]\n>     url = git@github.com:git/git.git\n>     fetch = +refs/heads/*:refs/remotes/origin/*\n>     fetch = ^refs/tags/v2.9.*\n>\n> run\n>   git fetch\n>\n> What did you expect to happen? (Expected behavior)\n>\n> To exclude tags matchings v2.9*, just like when running git fetch --tags\n>\n> What happened instead? (Actual behavior)\n>\n> Without specifying git fetch --tags, tags matching the negative\n> refspec are still fetched\n>\n> What's different between what you expected and what actually happened?\n>\n> The negative refspec appears to be ignored or overruled when running\n> git fetch without the --tags flag\n>\n> Anything else you want to add:\n> I love git, thank you! ♥\n>\n> Please review the rest of the bug report below.\n> You can delete any lines you don't wish to share.\n\nI haven't had time to try this, but I believe this isn't a bug, it's\njust that you didn't supply --no-tags.\n\n\"But I want some tags!\", yes, that's not what --no-tags does, see the\n2nd paragraph of the DESCRIPTION section of \"git-fetch\".\n\nI.e. it got stuff you asked for, but also tags pointing at the main\nhistory, --no-tags will stop that, at which point you can *also* fetch\ntags, just with the refspec.\n\n"},{"id":"464720","messageId":"CA+JQ7M-y9d=c3GbpAs+Y4qtimtVs9oQ6BU1YL8nmFmF=rZxKag@mail.gmail.com","threadId":"58607","inReplyTo":"221012.86mta1mmli.gmgdl@evledraar.gmail.com","subject":"Re: [BUG] git fetch fetches tags matching negative refspec","fromName":"Erik Cervin Edin","fromEmail":"erik@cervined.in","sentAt":"2022-10-12T15:10:46Z","receivedAt":"2022-10-12T15:11:01Z","isPatch":false,"sender":{"key":"erik@cervined.in","avatar":null},"body":"On Wed, Oct 12, 2022 at 11:13 AM Ævar Arnfjörð Bjarmason\n<avarab@gmail.com> wrote:\n> I.e. it got stuff you asked for, but also tags pointing at the main\n> history, --no-tags will stop that, at which point you can *also* fetch\n> tags, just with the refspec.\nI tried but\n  git fetch --no-tags\nwith negative refspec did not fetch any tags.\n  git fetch --tags\ndoes.\n\nI'm going to set\n  git config remote.origin.tagopt --tags\nand then that's going to do what I want.\n\nThank you for pointing me in the right direction and giving clarity.\n\n> I haven't had time to try this, but I believe this isn't a bug, it's\n> just that you didn't supply --no-tags.\nI guess then everything works as expected but maybe the documentation\nregarding this could be improved.\n"},{"id":"464789","messageId":"221013.865ygomybw.gmgdl@evledraar.gmail.com","threadId":"58607","inReplyTo":"CA+JQ7M-y9d=c3GbpAs+Y4qtimtVs9oQ6BU1YL8nmFmF=rZxKag@mail.gmail.com","subject":"Re: [BUG] git fetch fetches tags matching negative refspec","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-12T23:09:36Z","receivedAt":"2022-10-12T23:11:54Z","isPatch":false,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Wed, Oct 12 2022, Erik Cervin Edin wrote:\n\n> On Wed, Oct 12, 2022 at 11:13 AM Ævar Arnfjörð Bjarmason\n> <avarab@gmail.com> wrote:\n>> I.e. it got stuff you asked for, but also tags pointing at the main\n>> history, --no-tags will stop that, at which point you can *also* fetch\n>> tags, just with the refspec.\n> I tried but\n>   git fetch --no-tags\n> with negative refspec did not fetch any tags.\n>   git fetch --tags\n> does.\n\nBecause your refspec doesn't include refs/tags/*:, try e.g.:\n\n\tgit fetch https://github.com/git/git.git 'refs/tags/*:refs/tags/*' --no-tags --dry-run\n\nThat's what \"--no-tags\", i.e. it's per-se (and confusingly) nothing to\ndo with whether you get tags or not, it's to do with whether we to tag\nfollowing.\n\n> I'm going to set\n>   git config remote.origin.tagopt --tags\n> and then that's going to do what I want.\n\nIsn't that going to give you also the tags you don't want?\n"},{"id":"464802","messageId":"CA+JQ7M-YptXOT0jynaT3Lwka9cR3P-WFLeh7R1U=gEz+86Q-sg@mail.gmail.com","threadId":"58607","inReplyTo":"221013.865ygomybw.gmgdl@evledraar.gmail.com","subject":"Re: [BUG] git fetch fetches tags matching negative refspec","fromName":"Erik Cervin Edin","fromEmail":"erik@cervined.in","sentAt":"2022-10-13T08:15:33Z","receivedAt":"2022-10-13T08:16:14Z","isPatch":false,"sender":{"key":"erik@cervined.in","avatar":null},"body":"On Thu, Oct 13, 2022 at 1:11 AM Ævar Arnfjörð Bjarmason\n<avarab@gmail.com> wrote:\n>\n>\n> On Wed, Oct 12 2022, Erik Cervin Edin wrote:\n>\n> > On Wed, Oct 12, 2022 at 11:13 AM Ævar Arnfjörð Bjarmason\n> > <avarab@gmail.com> wrote:\n> >> I.e. it got stuff you asked for, but also tags pointing at the main\n> >> history, --no-tags will stop that, at which point you can *also* fetch\n> >> tags, just with the refspec.\n> > I tried but\n> >   git fetch --no-tags\n> > with negative refspec did not fetch any tags.\n> >   git fetch --tags\n> > does.\n>\n> Because your refspec doesn't include refs/tags/*:, try e.g.:\n>\n>         git fetch https://github.com/git/git.git 'refs/tags/*:refs/tags/*' --no-tags --dry-run\n>\n> That's what \"--no-tags\", i.e. it's per-se (and confusingly) nothing to\n> do with whether you get tags or not, it's to do with whether we to tag\n> following.\n\nKind of, adding the tags refspec with --no-tags excludes tags matching\nthe negative refspec but it also clobbers existing tags.\n\n>\n> > I'm going to set\n> >   git config remote.origin.tagopt --tags\n> > and then that's going to do what I want.\n>\n> Isn't that going to give you also the tags you don't want?\n\nNo, it excludes them fine. It also doesn't clobber which fits my use-case best\n"},{"id":"464828","messageId":"xmqqlepjivv4.fsf@gitster.g","threadId":"58607","inReplyTo":"221013.865ygomybw.gmgdl@evledraar.gmail.com","subject":"Re: [BUG] git fetch fetches tags matching negative refspec","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-10-13T15:30:55Z","receivedAt":"2022-10-13T15:31:09Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:\n\n> Because your refspec doesn't include refs/tags/*:, try e.g.:\n>\n> \tgit fetch https://github.com/git/git.git 'refs/tags/*:refs/tags/*' --no-tags --dry-run\n>\n> That's what \"--no-tags\", i.e. it's per-se (and confusingly) nothing to\n> do with whether you get tags or not, it's to do with whether we to tag\n> following.\n\nIt indeed is confusing and might warrant some clarification, if not\nupdating.\n\n * \"--tags\" is equivalent to giving \"refs/tags*:refs/tags*\", so it\n   might be natural to expect that you can say the same thing as\n   above with \"fetch $URL --tags --no-tags\", but it does not work\n   that way.  Command line parser treats \"--tags\" and \"--no-tags\" as\n   if they follow the \"last one wins\" semantics.\n\n * As discussed in this thread, what \"--no-tags\" really means is \"do\n   not follow tags\"; there is no way to countermand a \"--no-tags\"\n   earlier on the command line to say \"earlier we said do not\n   follow, but we changed our mind.  Please do follow tags\".\n\nIt would have been nice if we had from day one\n\n * \"--tags\": equivalent to writing \"refs/tags/*:refs/tags/*\"\n\n * \"--no-tags\": \"earlier we said --tags, but we changed our\n   mind. Please forget we earlier said --tags\".\n\n * \"--follow-tags\": automatically fetch tags that point at an\n   object that were fetched (default).\n\n * \"--no-follow-tags\": stop following tags.\n\nbut I do not think it is worth the churn and transition pain to\nchange it after more than 15 years.\n\n\n"},{"id":"465189","messageId":"CA+JQ7M_BoDbLM5_0Gvqfy0TTT_=4tvxG7mi+1ZYSNDTkSEoR6g@mail.gmail.com","threadId":"58607","inReplyTo":"xmqqlepjivv4.fsf@gitster.g","subject":"Re: [BUG] git fetch fetches tags matching negative refspec","fromName":"Erik Cervin Edin","fromEmail":"erik@cervined.in","sentAt":"2022-10-18T12:40:48Z","receivedAt":"2022-10-18T12:41:30Z","isPatch":false,"sender":{"key":"erik@cervined.in","avatar":null},"body":"On Thu, Oct 13, 2022 at 5:31 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> It indeed is confusing and might warrant some clarification, if not\n> updating.\n>\n>  * \"--tags\" is equivalent to giving \"refs/tags*:refs/tags*\", so it\n>    might be natural to expect that you can say the same thing as\n>    above with \"fetch $URL --tags --no-tags\", but it does not work\n>    that way.  Command line parser treats \"--tags\" and \"--no-tags\" as\n>    if they follow the \"last one wins\" semantics.\n>\n>  * As discussed in this thread, what \"--no-tags\" really means is \"do\n>    not follow tags\"; there is no way to countermand a \"--no-tags\"\n>    earlier on the command line to say \"earlier we said do not\n>    follow, but we changed our mind.  Please do follow tags\".\n\nThank you for the clarification.\n\nWhat follows is a small write-up of my problem for posterity and\nin-case someone else finds it useful.\n\nWhat I'm trying to achieve is by default excluding a set of tags auto\ngenerated build tags from being fetched, unless I specifically fetch\nthem.\n\nSomething akin to this works\n  [remote \"origin\"]\n      url = git@github.com:git/git.git\n      fetch = +refs/heads/*:refs/remotes/origin/*\n      fetch = ^refs/tags/v2.9.*\n      tagOpt = --no-tags\n\nThis lets me\n  git fetch\n  git fetch origin master\nwithout fetching tags matching the negative refspec, as expected. As\nwell as override it through\n  git fetch origin '+refs/tags/v2.9.0*:refs/tags/v2.9.0*'\nwhich isn't super friendly to write but does the job\n\n\nEarlier in the thread, I was under the impression --tags worked better\nthan --no-tags. It seemed it would avoid clobbering tags. I don't\nthink that's actually the case (they both clobber?) and it turned out\nit wouldn't exclude refs if I was fetching a specific ref, ie\n  git fetch origin master\nwould also fetch the tags I didn't want. So --no-tags it is\n"}]}