{"thread":{"id":"53983","subject":"avoiding fetching specific refs from a remote","startedAt":"2020-08-04T21:53:47Z","lastAt":"2020-08-13T08:48:18Z","messageCount":10,"participants":["Jacob Keller","Jeff King","Junio C Hamano","Philippe Blain","Eric Wong"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"402851","messageId":"CA+P7+xpokJ3Z4xZ9ibCBpBO65D1v-AD6_JknprGUsEDxEvMGGw@mail.gmail.com","threadId":"53983","inReplyTo":null,"subject":"avoiding fetching specific refs from a remote","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2020-08-04T21:53:30Z","receivedAt":"2020-08-04T21:53:47Z","isPatch":false,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"Hi,\n\nI've recently had a few repositories switch their default branch from\nmaster to main. Currently, for backwards compatibility these\nrepositories have kept master around as a synonym for main. It's\nunclear when this will be removed.\n\nThis results in the annoying completion behavior where:\n\n$git checkout ma<TAB>\nmain\nmaster\n\nEssentially, because both main and master have similar names, tab\ncompletion requires remembering to type one additional character than\nI am used to.\n\nI'd like to be able to customize my pull so that I either (a) exclude\nthe reference when performing a fetch, or (b) exclude the reference\nwhen tab completing.\n\nI don't know if there is any mechanism already in place to do this, so\nI'm trying to figure out which one would be most preferable on the\nlist?\n\nsomething like adding a remote.<name>.excludeRefs which would allow\nspecifying a set of references to exclude from matching the refspec..\n\nI realize I could customize the refspec to list the set of things I\nwant, but then I would miss any potential future branches until I\nupdated my remote config again.\n\nI would like to be able to remove this annoyance for myself and colleagues.\n\nIt seems to me the easiest solution would be the sort of exclude\noption, as this enables generally skipping out on specific refs, and\ncould be useful beyond just this initial impetus.\n\nThanks,\nJake\n"},{"id":"402896","messageId":"20200805063704.GA2690083@coredump.intra.peff.net","threadId":"53983","inReplyTo":"CA+P7+xpokJ3Z4xZ9ibCBpBO65D1v-AD6_JknprGUsEDxEvMGGw@mail.gmail.com","subject":"Re: avoiding fetching specific refs from a remote","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-08-05T06:37:04Z","receivedAt":"2020-08-05T06:37:07Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Aug 04, 2020 at 02:53:30PM -0700, Jacob Keller wrote:\n\n> This results in the annoying completion behavior where:\n> \n> $git checkout ma<TAB>\n> main\n> master\n> \n> Essentially, because both main and master have similar names, tab\n> completion requires remembering to type one additional character than\n> I am used to.\n\nHeh, I didn't think anybody considered that implication so far; the fact\nthat they were similar names has generally been considered a positive. I\nagree it would be annoying.\n\n> I'd like to be able to customize my pull so that I either (a) exclude\n> the reference when performing a fetch, or (b) exclude the reference\n> when tab completing.\n\nNot quite (b), but if you:\n\n  - delete any local \"master\" branch, if you haven't already\n\n  - set $GIT_COMPLETION_CHECKOUT_NO_GUESS to \"1\"\n\nthen it shouldn't complete \"master\". The second is necessary because\nwe'd try to complete the magic \"git checkout master\" that auto-creates\nthe branch from the remote version.\n\n> something like adding a remote.<name>.excludeRefs which would allow\n> specifying a set of references to exclude from matching the refspec..\n> \n> I realize I could customize the refspec to list the set of things I\n> want, but then I would miss any potential future branches until I\n> updated my remote config again.\n\nThis is definitely a reasonable thing to want, and it has come up off\nand on over the years. One search term for the list archive is \"negative\nrefspecs\", though it turns up a lot of useless hits when the two words\nare not directly adjacent.\n\nThis old thread might be worth reading:\n\n  https://lore.kernel.org/git/20140124090104.GA396@x4/\n\nand there is even a patch in there:\n\n  https://lore.kernel.org/git/20140125013433.GA22336@sigill.intra.peff.net/\n\nbut I didn't go over it carefully enough to know whether it is utter\ntrash, or something that could be used as a starting point.\n\n-Peff\n"},{"id":"402957","messageId":"xmqq1rkloyeg.fsf@gitster.c.googlers.com","threadId":"53983","inReplyTo":"20200805063704.GA2690083@coredump.intra.peff.net","subject":"Re: avoiding fetching specific refs from a remote","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-08-05T16:22:47Z","receivedAt":"2020-08-05T20:14:04Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n>> Essentially, because both main and master have similar names, tab\n>> completion requires remembering to type one additional character than\n>> I am used to.\n>\n> Heh, I didn't think anybody considered that implication so far; the fact\n> that they were similar names has generally been considered a positive. I\n> agree it would be annoying.\n\nFWIW, I've been saying that 'maint' will become harder to type all\nalong ever since I heard 'main'.\n\nhttps://lore.kernel.org/git/xmqqtuz9tq30.fsf@gitster.c.googlers.com/\n\n> This is definitely a reasonable thing to want, and it has come up off\n> and on over the years. One search term for the list archive is \"negative\n> refspecs\", though it turns up a lot of useless hits when the two words\n> are not directly adjacent.\n>\n> This old thread might be worth reading:\n>\n>   https://lore.kernel.org/git/20140124090104.GA396@x4/\n>\n> and there is even a patch in there:\n>\n>   https://lore.kernel.org/git/20140125013433.GA22336@sigill.intra.peff.net/\n>\n> but I didn't go over it carefully enough to know whether it is utter\n> trash, or something that could be used as a starting point.\n\nI think the idea is interesting.  I sometimes find negative\npathspecs quite useful, and I suspect negative refspecs would also\nbe.\n"},{"id":"402959","messageId":"CA+P7+xofEHdvVOy-9RLUF=kXCjNEXrs0M3Mp6h8RgehY2KHaaw@mail.gmail.com","threadId":"53983","inReplyTo":"20200805063704.GA2690083@coredump.intra.peff.net","subject":"Re: avoiding fetching specific refs from a remote","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2020-08-05T20:31:55Z","receivedAt":"2020-08-05T20:32:11Z","isPatch":false,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Tue, Aug 4, 2020 at 11:37 PM Jeff King <peff@peff.net> wrote:\n>\n> On Tue, Aug 04, 2020 at 02:53:30PM -0700, Jacob Keller wrote:\n>\n> > This results in the annoying completion behavior where:\n> >\n> > $git checkout ma<TAB>\n> > main\n> > master\n> >\n> > Essentially, because both main and master have similar names, tab\n> > completion requires remembering to type one additional character than\n> > I am used to.\n>\n> Heh, I didn't think anybody considered that implication so far; the fact\n> that they were similar names has generally been considered a positive. I\n> agree it would be annoying.\n>\n> > I'd like to be able to customize my pull so that I either (a) exclude\n> > the reference when performing a fetch, or (b) exclude the reference\n> > when tab completing.\n>\n> Not quite (b), but if you:\n>\n>   - delete any local \"master\" branch, if you haven't already\n>\n>   - set $GIT_COMPLETION_CHECKOUT_NO_GUESS to \"1\"\n>\n> then it shouldn't complete \"master\". The second is necessary because\n> we'd try to complete the magic \"git checkout master\" that auto-creates\n> the branch from the remote version.\n>\n\nI don't like this approach because I like having the guessing options\navailable in most repositories.\n\n> > something like adding a remote.<name>.excludeRefs which would allow\n> > specifying a set of references to exclude from matching the refspec..\n> >\n> > I realize I could customize the refspec to list the set of things I\n> > want, but then I would miss any potential future branches until I\n> > updated my remote config again.\n>\n> This is definitely a reasonable thing to want, and it has come up off\n> and on over the years. One search term for the list archive is \"negative\n> refspecs\", though it turns up a lot of useless hits when the two words\n> are not directly adjacent.\n>\n> This old thread might be worth reading:\n>\n>   https://lore.kernel.org/git/20140124090104.GA396@x4/\n>\n> and there is even a patch in there:\n>\n>   https://lore.kernel.org/git/20140125013433.GA22336@sigill.intra.peff.net/\n>\n> but I didn't go over it carefully enough to know whether it is utter\n> trash, or something that could be used as a starting point.\n>\n\nThanks, it looks like this is at least sensible.\n\n> -Peff\n"},{"id":"402961","messageId":"CA+P7+xrAyCgYyh4_WM5hcBv8+WXaRvN_Cf6nqz4ruO4oHzwjvQ@mail.gmail.com","threadId":"53983","inReplyTo":"xmqq1rkloyeg.fsf@gitster.c.googlers.com","subject":"Re: avoiding fetching specific refs from a remote","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2020-08-05T20:34:08Z","receivedAt":"2020-08-05T20:34:25Z","isPatch":false,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Wed, Aug 5, 2020 at 9:22 AM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Jeff King <peff@peff.net> writes:\n>\n> >> Essentially, because both main and master have similar names, tab\n> >> completion requires remembering to type one additional character than\n> >> I am used to.\n> >\n> > Heh, I didn't think anybody considered that implication so far; the fact\n> > that they were similar names has generally been considered a positive. I\n> > agree it would be annoying.\n>\n> FWIW, I've been saying that 'maint' will become harder to type all\n> along ever since I heard 'main'.\n>\n> https://lore.kernel.org/git/xmqqtuz9tq30.fsf@gitster.c.googlers.com/\n>\n\nRight. I'm generally for the name change, and I like having the remote\nhonor the old name as a compatibility at least for some duration.\n\n> > This is definitely a reasonable thing to want, and it has come up off\n> > and on over the years. One search term for the list archive is \"negative\n> > refspecs\", though it turns up a lot of useless hits when the two words\n> > are not directly adjacent.\n> >\n> > This old thread might be worth reading:\n> >\n> >   https://lore.kernel.org/git/20140124090104.GA396@x4/\n> >\n> > and there is even a patch in there:\n> >\n> >   https://lore.kernel.org/git/20140125013433.GA22336@sigill.intra.peff.net/\n> >\n> > but I didn't go over it carefully enough to know whether it is utter\n> > trash, or something that could be used as a starting point.\n>\n> I think the idea is interesting.  I sometimes find negative\n> pathspecs quite useful, and I suspect negative refspecs would also\n> be.\n\nI've found negative pathspecs incredibly useful in some contexts,\n(with my only issue being to remember that if you specify a negative\npathspec, you must also specify a positive one i.e. \".\" or something)\n\nI think I'll try to revive that one patch Peff pointed out and then\nsee if it makes sense or needs to be redone.\n"},{"id":"402962","messageId":"20200805203425.GA2706898@coredump.intra.peff.net","threadId":"53983","inReplyTo":"xmqq1rkloyeg.fsf@gitster.c.googlers.com","subject":"Re: avoiding fetching specific refs from a remote","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-08-05T20:34:25Z","receivedAt":"2020-08-05T20:34:38Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Aug 05, 2020 at 09:22:47AM -0700, Junio C Hamano wrote:\n\n> Jeff King <peff@peff.net> writes:\n> \n> >> Essentially, because both main and master have similar names, tab\n> >> completion requires remembering to type one additional character than\n> >> I am used to.\n> >\n> > Heh, I didn't think anybody considered that implication so far; the fact\n> > that they were similar names has generally been considered a positive. I\n> > agree it would be annoying.\n> \n> FWIW, I've been saying that 'maint' will become harder to type all\n> along ever since I heard 'main'.\n> \n> https://lore.kernel.org/git/xmqqtuz9tq30.fsf@gitster.c.googlers.com/\n\nTrue, but I thought that was just a reason against \"main\" in git.git\nitself. Most repos don't have \"maint\" (and we already conflicted on \"ma\"\nwith the existing name :) though I agree that having one as a prefix of\nthe other makes completion doubly painful). The interesting bit here is\nthat the old name probably _isn't_ going away immediately, so this would\naffect everybody.\n\n-Peff\n"},{"id":"402993","messageId":"BE29FA64-5281-4D9E-B509-CA2C2B7BB87D@gmail.com","threadId":"53983","inReplyTo":"20200805063704.GA2690083@coredump.intra.peff.net","subject":"Re: avoiding fetching specific refs from a remote","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2020-08-05T22:12:42Z","receivedAt":"2020-08-05T22:13:00Z","isPatch":false,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Peff,\n\n> Le 5 août 2020 à 02:37, Jeff King <peff@peff.net> a écrit :\n> \n> On Tue, Aug 04, 2020 at 02:53:30PM -0700, Jacob Keller wrote:\n> \n>> something like adding a remote.<name>.excludeRefs which would allow\n>> specifying a set of references to exclude from matching the refspec..\n>> \n>> I realize I could customize the refspec to list the set of things I\n>> want, but then I would miss any potential future branches until I\n>> updated my remote config again.\n> \n> This is definitely a reasonable thing to want, and it has come up off\n> and on over the years. One search term for the list archive is \"negative\n> refspecs\", though it turns up a lot of useless hits when the two words\n> are not directly adjacent.\n\nI tried searching \"negative refspecs\" (*with* the double quotes) and I get 20 results so it \nseems to work. Although interestingly it doesn't find this message you wrote I'm responding to \nbecause \"negative\" and \"refspec\" are on separate lines... I'm CC-ing Eric in case he knows more\nabout this limitation.\n\nPhilippe.\n\n\n"},{"id":"403122","messageId":"20200807080436.GA21342@dcvr","threadId":"53983","inReplyTo":"BE29FA64-5281-4D9E-B509-CA2C2B7BB87D@gmail.com","subject":"Re: avoiding fetching specific refs from a remote","fromName":"Eric Wong","fromEmail":"e@80x24.org","sentAt":"2020-08-07T08:04:36Z","receivedAt":"2020-08-07T08:04:38Z","isPatch":false,"sender":{"key":"e@80x24.org","avatar":null},"body":"Philippe Blain <levraiphilippeblain@gmail.com> wrote:\n> > Le 5 août 2020 à 02:37, Jeff King <peff@peff.net> a écrit :\n> > This is definitely a reasonable thing to want, and it has come up off\n> > and on over the years. One search term for the list archive is \"negative\n> > refspecs\", though it turns up a lot of useless hits when the two words\n> > are not directly adjacent.\n> \n> I tried searching \"negative refspecs\" (*with* the double quotes) and I get 20 results so it \n> seems to work. Although interestingly it doesn't find this message you wrote I'm responding to \n> because \"negative\" and \"refspec\" are on separate lines... I'm CC-ing Eric in case he knows more\n> about this limitation.\n\nInitially I thought it was phrase searching being disabled\non lore (Xapian 1.2, \"chert\" backend).  However, I just\ntried on lore and it shows Jeff's message from\n2020-08-05 6:37 UTC:\n\n https://lore.kernel.org/git/?q=%22negative+refspecs%22\n\nSo maybe it was a delay due to Xapian's MVCC mechanism;\nbut that shouldn't be HOURS off (maybe minutes at most),\nassuming you tried to search shortly before you sent\nthe message I'm replying to at 22:12 UTC...\n\nMy v1 instance at public-inbox.org (which uses Xapian 1.4\nand the \"glass\" backend) shows it, too:\n\n https://public-inbox.org/git/?q=%22negative+refspecs%22\n\nYou could also try NEAR and ADJ (I don't have much experience\nwith those): https://xapian.org/docs/queryparser.html\n"},{"id":"403510","messageId":"CA+P7+xp5aRWV0udmf03+ox4+8nCOmXtfEckmhJrAs-42Tomn0w@mail.gmail.com","threadId":"53983","inReplyTo":"20200805063704.GA2690083@coredump.intra.peff.net","subject":"Re: avoiding fetching specific refs from a remote","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2020-08-12T22:04:09Z","receivedAt":"2020-08-12T22:04:24Z","isPatch":false,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Tue, Aug 4, 2020 at 11:37 PM Jeff King <peff@peff.net> wrote:\n>\n> On Tue, Aug 04, 2020 at 02:53:30PM -0700, Jacob Keller wrote:\n>\n> > This results in the annoying completion behavior where:\n> >\n> > $git checkout ma<TAB>\n> > main\n> > master\n> >\n> > Essentially, because both main and master have similar names, tab\n> > completion requires remembering to type one additional character than\n> > I am used to.\n>\n> Heh, I didn't think anybody considered that implication so far; the fact\n> that they were similar names has generally been considered a positive. I\n> agree it would be annoying.\n>\n> > I'd like to be able to customize my pull so that I either (a) exclude\n> > the reference when performing a fetch, or (b) exclude the reference\n> > when tab completing.\n>\n> Not quite (b), but if you:\n>\n>   - delete any local \"master\" branch, if you haven't already\n>\n>   - set $GIT_COMPLETION_CHECKOUT_NO_GUESS to \"1\"\n>\n> then it shouldn't complete \"master\". The second is necessary because\n> we'd try to complete the magic \"git checkout master\" that auto-creates\n> the branch from the remote version.\n>\n> > something like adding a remote.<name>.excludeRefs which would allow\n> > specifying a set of references to exclude from matching the refspec..\n> >\n> > I realize I could customize the refspec to list the set of things I\n> > want, but then I would miss any potential future branches until I\n> > updated my remote config again.\n>\n> This is definitely a reasonable thing to want, and it has come up off\n> and on over the years. One search term for the list archive is \"negative\n> refspecs\", though it turns up a lot of useless hits when the two words\n> are not directly adjacent.\n>\n> This old thread might be worth reading:\n>\n>   https://lore.kernel.org/git/20140124090104.GA396@x4/\n>\n> and there is even a patch in there:\n>\n>   https://lore.kernel.org/git/20140125013433.GA22336@sigill.intra.peff.net/\n>\n> but I didn't go over it carefully enough to know whether it is utter\n> trash, or something that could be used as a starting point.\n>\n> -Peff\n\nI dug up the patch and have applied it to master. One concern I have\nis how do we tell what side the negative refspec applies to? It seems\nlike we'd need to be able to distinguish whether it applies to the\nrefname on the remote, or the refname on the local branch. The patch\nas-is assumes that negative refspecs only ever have \"src\".. I guess\nfor fetch that means the name of the ref on the remote, and for push\nthat means the name of the ref on the local end?\n\nI was trying to modify the patch to add support to the push code flows\nso that it was more complete and could be submitted. I'll be sending\nwhat I have as an RFC soon.\n\nThanks,\nJake\n"},{"id":"403532","messageId":"20200813084815.GA3092220@coredump.intra.peff.net","threadId":"53983","inReplyTo":"CA+P7+xp5aRWV0udmf03+ox4+8nCOmXtfEckmhJrAs-42Tomn0w@mail.gmail.com","subject":"Re: avoiding fetching specific refs from a remote","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-08-13T08:48:15Z","receivedAt":"2020-08-13T08:48:18Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Aug 12, 2020 at 03:04:09PM -0700, Jacob Keller wrote:\n\n> I dug up the patch and have applied it to master. One concern I have\n> is how do we tell what side the negative refspec applies to? It seems\n> like we'd need to be able to distinguish whether it applies to the\n> refname on the remote, or the refname on the local branch. The patch\n> as-is assumes that negative refspecs only ever have \"src\".. I guess\n> for fetch that means the name of the ref on the remote, and for push\n> that means the name of the ref on the local end?\n\nYeah, unlike a normal refspec that can have both a src and dst, there\nreally is only one \"side\" to a negative refspec, because it is not going\nanywhere. So selecting by src makes the most sense to me. We could also\nallow selecting by dst, like:\n\n  git fetch origin refs/heads/*:refs/remotes/origin/* \\\n    ^refs/heads/foo           \\ (1) omit remote foo branch; implies src\n    ^refs/heads/bar:          \\ (2) omit remote bar branch by explicit src\n    ^:refs/remotes/origin/baz   (3) omit remote baz branch by explicit dst\n\nI probably wouldn't bother with (2) or (3) unless somebody really wants\nthem. We can do (1) now and then extend later without loss of\ncompatibility.\n\nAnother thing to think about is how to handle overlap. E.g., in:\n\n  ^refs/heads/foo refs/heads/*:refs/remotes/origin/*\n\nshould:\n\n  1. The first take precedence over the second because we apply\n     positive, then negative?\n\n  2. Or should it be first over second because the first is specific and\n     the second is a wildcard?\n\n  3. Or should it be second over first because later refspecs override\n     earlier?\n\nI don't have a real preference, and I think there are many\nself-consistent schemes you could come up with. But it probably makes\nsense to think it through so that we don't get stuck supporting a\nhalf-baked behavior later.\n\n> I was trying to modify the patch to add support to the push code flows\n> so that it was more complete and could be submitted. I'll be sending\n> what I have as an RFC soon.\n\nSounds good. Thanks for picking this up!\n\n-Peff\n"}]}