{"thread":{"id":"49364","subject":"Cannot negate `*` ignore pattern for directory with space in the name","startedAt":"2018-09-18T04:11:53Z","lastAt":"2018-09-18T21:03:16Z","messageCount":3,"participants":["Victor Engmark","Duy Nguyen"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"358384","messageId":"955f404f-83ed-758e-017b-d6b4a1f69ef7@catalyst.net.nz","threadId":"49364","inReplyTo":null,"subject":"Cannot negate `*` ignore pattern for directory with space in the name","fromName":"Victor Engmark","fromEmail":"victorengmark@catalyst.net.nz","sentAt":"2018-09-18T04:03:33Z","receivedAt":"2018-09-18T04:11:53Z","isPatch":false,"sender":{"key":"victorengmark@catalyst.net.nz","avatar":null},"body":"To reproduce (from <https://unix.stackexchange.com/q/469708/3645>):\n\n$ cd \"$(mktemp --directory)\"\n$ mkdir foo\\ bar\n$ touch foo\\ bar/test\n$ git init\nInitialized empty Git repository in /tmp/tmp.iGmBR6y2xR/.git/\n$ git status --short\n?? foo bar/\n$ cat > .gitignore << EOF\n> *\n> !foo bar\n> !foo\\ bar\n> !\"foo bar\"\n> \"!foo bar\"\n> !foo*\n> !foo bar/\n> !foo\\ bar/\n> !\"foo bar/\"\n> \"!foo bar/\"\n> !foo*/\n> EOF\n$ git status --short\n[no output]\n\nThe pattern *can* be negated if it only matches directories:\n\n$ cat > .gitignore << EOF\n> */\n> !foo\\ bar/\n> EOF\n$ git status --short\n?? .gitignore\n?? foo bar/\n\nI encountered this problem because Visual Studio Code creates a\nconfiguration directory called \"Code - OSS\", and I exclude everything in\n~/.config by default to avoid noise in `git status`.\n\n$ git --version\ngit version 2.19.0\n\n-- \nKind regards\nVictor Engmark\n"},{"id":"358408","messageId":"CACsJy8Cbp+1-CXMup4m=qLgJA511X0NtM51sFma_8nmp4_EhKg@mail.gmail.com","threadId":"49364","inReplyTo":"955f404f-83ed-758e-017b-d6b4a1f69ef7@catalyst.net.nz","subject":"Re: Cannot negate `*` ignore pattern for directory with space in the name","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-09-18T17:59:07Z","receivedAt":"2018-09-18T17:59:36Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Sep 18, 2018 at 6:13 AM Victor Engmark\n<victorengmark@catalyst.net.nz> wrote:\n>\n> To reproduce (from <https://unix.stackexchange.com/q/469708/3645>):\n>\n> $ cd \"$(mktemp --directory)\"\n> $ mkdir foo\\ bar\n> $ touch foo\\ bar/test\n> $ git init\n> Initialized empty Git repository in /tmp/tmp.iGmBR6y2xR/.git/\n> $ git status --short\n> ?? foo bar/\n> $ cat > .gitignore << EOF\n> > *\n> > !foo bar\n> > !foo\\ bar\n> > !\"foo bar\"\n\nNo need to quote, either with double quotes or backslashes. They are\ninterpreted as literal \" and \\\n\n> $ git status --short\n> [no output]\n\nIt's not exactly a bug, more like a trap. '*' matches anything, at\nevery level. So even if you negate 'foo bar', when we check 'foo\nbar/test', '*' pattern applies again and ignores 'foo bar/test'. If\nthe first line in .gitignore is /* instead of * (to keep match\nanything at the top level directory only), then it should work.\n-- \nDuy\n"},{"id":"358415","messageId":"4af0a71a-4b25-f09c-b238-3264e7a49058@catalyst.net.nz","threadId":"49364","inReplyTo":"CACsJy8Cbp+1-CXMup4m=qLgJA511X0NtM51sFma_8nmp4_EhKg@mail.gmail.com","subject":"Re: Cannot negate `*` ignore pattern for directory with space in the name","fromName":"Victor Engmark","fromEmail":"victorengmark@catalyst.net.nz","sentAt":"2018-09-18T21:03:12Z","receivedAt":"2018-09-18T21:03:16Z","isPatch":false,"sender":{"key":"victorengmark@catalyst.net.nz","avatar":null},"body":"On 19/09/2018 05:59, Duy Nguyen wrote:\n> On Tue, Sep 18, 2018 at 6:13 AM Victor Engmark\n> <victorengmark@catalyst.net.nz> wrote:\n[…]\n>> $ cat > .gitignore << EOF\n>>> *\n>>> !foo bar\n>>> !foo\\ bar\n>>> !\"foo bar\"\n> \n> No need to quote, either with double quotes or backslashes. They are\n> interpreted as literal \" and \\\n\nThanks! I just tried a bunch of things to see if anything stuck.\n\n>> $ git status --short\n>> [no output]\n> \n> It's not exactly a bug, more like a trap. '*' matches anything, at\n> every level. So even if you negate 'foo bar', when we check 'foo\n> bar/test', '*' pattern applies again and ignores 'foo bar/test'. If\n> the first line in .gitignore is /* instead of * (to keep match\n> anything at the top level directory only), then it should work.\n\nYou're right, I've managed to induce the placebo effect in myself :)\nThank you for the help, and sorry for the noise!\n\n-- \nCheers\nVictor\n"}]}