{"thread":{"id":"60479","subject":"Bug: magic-less pathspecs that start with \":\" not processed as expected.","startedAt":"2023-11-06T15:54:17Z","lastAt":"2023-11-07T03:25:15Z","messageCount":5,"participants":["Joanna Wang","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"484464","messageId":"CAMmZTi-JJ6=Uw_+r50hKMYf34D0NtqXhaA=f+11+wAQBjqA7_g@mail.gmail.com","threadId":"60479","inReplyTo":null,"subject":"Bug: magic-less pathspecs that start with \":\" not processed as expected.","fromName":"Joanna Wang","fromEmail":"jojwang@google.com","sentAt":"2023-11-06T15:54:03Z","receivedAt":"2023-11-06T15:54:17Z","isPatch":false,"sender":{"key":"jojwang@google.com","avatar":"https://avatars.githubusercontent.com/u/120585822?v=4"},"body":"What did you do before the bug happened? (Steps to reproduce your issue)\n\nWhat did you expect to happen? (Expected behavior)\n`git stash push -- :file` where `:` is part of the filename, should search\nfor files named \":file\"\n\nWhat happened instead? (Actual behavior)\nThe match string used to find files is \"file\" without the \":\".\n\nWhat's different between what you expected and what actually happened?\nfile named \":file\" is not found.\n\nAnything else you want to add:\nI believe this is due to parse_short_magic() not handling the case where\n\":\" is part of the file name rather than a prefix for pathspec magic.\n\nI could not find any documentation that says \":\" is a reserved\ncharacter to indicate pathspec magic symbols MUST follow or that\n\":file\" is not a valid file name.\n\n[System Info]\ngit version 2.42.0\ncpu: x86_64\nno commit associated with this build\nshell-path: /bin/sh\n\n[Enabled Hooks]\nnot run from a git repository - no hooks to show\n"},{"id":"484468","messageId":"20231106173133.GC10414@coredump.intra.peff.net","threadId":"60479","inReplyTo":"CAMmZTi-JJ6=Uw_+r50hKMYf34D0NtqXhaA=f+11+wAQBjqA7_g@mail.gmail.com","subject":"Re: Bug: magic-less pathspecs that start with \":\" not processed as expected.","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2023-11-06T17:31:33Z","receivedAt":"2023-11-06T17:31:36Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Nov 06, 2023 at 10:54:03AM -0500, Joanna Wang wrote:\n\n> What did you do before the bug happened? (Steps to reproduce your issue)\n> \n> What did you expect to happen? (Expected behavior)\n> `git stash push -- :file` where `:` is part of the filename, should search\n> for files named \":file\"\n> \n> What happened instead? (Actual behavior)\n> The match string used to find files is \"file\" without the \":\".\n> \n> What's different between what you expected and what actually happened?\n> file named \":file\" is not found.\n> \n> Anything else you want to add:\n> I believe this is due to parse_short_magic() not handling the case where\n> \":\" is part of the file name rather than a prefix for pathspec magic.\n> \n> I could not find any documentation that says \":\" is a reserved\n> character to indicate pathspec magic symbols MUST follow or that\n> \":file\" is not a valid file name.\n\nI think this is the correct behavior according to the documentation.\nFrom \"git help glossary\", the entry on \"pathspec\" says:\n\n  A pathspec that begins with a colon : has special meaning. In the\n  short form, the leading colon : is followed by zero or more \"magic\n  signature\" letters (which optionally is terminated by another colon\n  :), and the remainder is the pattern to match against the path.\n\nSo \":file\" just has zero magic signature letters. I think you want:\n\n  :::file\n\nwhich of course is rather ugly, but then so is your filename. ;)\nAlthough longer, probably this is more readable:\n\n  :(literal):file\n\nAnd if you're working with a lot of such files (or you are scripting and\nknow you have a set of filenames), then your best bet is probably\nturning on literal mode, like:\n\n  git --literal-pathspecs ls-files -- :file\n\n-Peff\n\nPS It took me a while to figure out where we document pathspec syntax. I\n   wonder if a \"gitpathspecs\" manpage would make sense, like we have\n   \"gitrevisions\".\n"},{"id":"484481","messageId":"xmqqlebacvn3.fsf@gitster.g","threadId":"60479","inReplyTo":"CAMmZTi-JJ6=Uw_+r50hKMYf34D0NtqXhaA=f+11+wAQBjqA7_g@mail.gmail.com","subject":"Re: Bug: magic-less pathspecs that start with \":\" not processed as expected.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-11-06T23:25:04Z","receivedAt":"2023-11-06T23:25:15Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Joanna Wang <jojwang@google.com> writes:\n\n> I believe this is due to parse_short_magic() not handling the case where\n> \":\" is part of the file name rather than a prefix for pathspec magic.\n\nAlso, \":<path>\" is a notation for the object name sitting at <path>\nin the index, so giving it from the command line is ambiguous, too.\nI thought that ./:<path> would be a common way to talk about such a\npath to git commands?\n\n    $ date >./:now.txt\n    $ git add ./:now.txt\n    $ git rm ./:now.txt\n\nI do not offhand remember where this is documented, but I agree that\nwe need to make sure that we give help to users on things like this\n(\"how do I add a file whose name begins with a dash\" is another\nquestion I think we hear from time to time).\n\nThanks.\n"},{"id":"484482","messageId":"xmqqfs1icvfl.fsf@gitster.g","threadId":"60479","inReplyTo":"20231106173133.GC10414@coredump.intra.peff.net","subject":"Re: Bug: magic-less pathspecs that start with \":\" not processed as expected.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-11-06T23:29:34Z","receivedAt":"2023-11-06T23:29:41Z","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> PS It took me a while to figure out where we document pathspec syntax. I\n>    wonder if a \"gitpathspecs\" manpage would make sense, like we have\n>    \"gitrevisions\".\n\nYeah, I came to the same conclusion (should have saved time by\nscanning the mailing list before I started writing my response) and\nwondered where we wrote it down.  The description you found in the\nglossary, as far as I recall, is the authoritative one and looks\nreadable, but I agree it is not as discoverable as it should be.\n\nA simpler and more readable workaround than \":::file\" is \"./:file\"\nby the way ;-)\n\n"},{"id":"484506","messageId":"20231107032144.GA873619@coredump.intra.peff.net","threadId":"60479","inReplyTo":"xmqqfs1icvfl.fsf@gitster.g","subject":"Re: Bug: magic-less pathspecs that start with \":\" not processed as expected.","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2023-11-07T03:25:11Z","receivedAt":"2023-11-07T03:25:15Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Nov 07, 2023 at 08:29:34AM +0900, Junio C Hamano wrote:\n\n> Jeff King <peff@peff.net> writes:\n> \n> > PS It took me a while to figure out where we document pathspec syntax. I\n> >    wonder if a \"gitpathspecs\" manpage would make sense, like we have\n> >    \"gitrevisions\".\n> \n> Yeah, I came to the same conclusion (should have saved time by\n> scanning the mailing list before I started writing my response) and\n> wondered where we wrote it down.  The description you found in the\n> glossary, as far as I recall, is the authoritative one and looks\n> readable, but I agree it is not as discoverable as it should be.\n> \n> A simpler and more readable workaround than \":::file\" is \"./:file\"\n> by the way ;-)\n\nOh, indeed. That is much less horrible than \":(literal)\". :)\n\n-Peff\n"}]}