git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: the opposite of .gitignore, whitelist

From
JCJason Cooper <git@lakedaemon.net>
Date
Oct 26, 2018, 15:27 UTC
Message-ID
<20181026152754.GF24185@io.lakedaemon.net>
In-Reply-To
<20181026133453.GE24185@io.lakedaemon.net>
On Fri, Oct 26, 2018 at 01:34:53PM +0000, Jason Cooper wrote:
> On Fri, Oct 26, 2018 at 02:39:26PM +0200, Ævar Arnfjörð Bjarmason wrote:
...
Show 25 quoted lines
> >     I thought this was a bug:
> > 
> >         (
> >             rm -rf /tmp/git &&
> >             git init /tmp/git &&
> >             cd /tmp/git >/dev/null &&
> >             echo '*' >.gitignore &&
> >             echo '!*.txt' >>.gitignore &&
> >             echo '!.gitignore' >>.gitignore &&
> >             touch foo.png foo.txt &&
> >             mkdir dir &&
> >             touch dir/bar.png dir/bar.txt &&
> >             git add *.txt &&
> >             git add */*.txt;
> >             git status --short
> >         )
> > 
> >     But it's a limitation, gitignore(5) says:
> > 
> >         It is not possible to re-include a file if a parent directory of
> >         that file is excluded. Git doesn’t list excluded directories for
> >         performance reasons, so any patterns on contained files have no
> >         effect, no matter where they are defined.
> 
> Bingo.  This is the exact problem I encountered.
(
    rm -rf /tmp/git &&
    git init /tmp/git &&
    cd /tmp/git >/dev/null &&
    echo '*' >.gitignore &&
    echo '!dir/' >>.gitignore &&
    echo '!*.txt' >>.gitignore &&
    echo '!.gitignore' >>.gitignore &&
    touch foo.png foo.txt &&
    mkdir dir &&
    echo '*' >dir/.gitignore &&
    echo '!*.txt' >>dir/.gitignore &&
    echo '!.gitignore' >>dir/.gitignore &&
    touch dir/bar.png dir/bar.txt &&
    git add *.txt &&
    git add */*.txt;
    git status --short
)
Well, this wfm...
Ugly, but doable.
thx,
Jason.
Previous: Jason Cooper
Message 10 of 10 in “the opposite of .gitignore, whitelist”
  1. lhf635@163.comOct 25, 2018
  2. Junio C HamanoOct 25, 2018
  3. Jason CooperOct 25, 2018
  4. Jeff KingOct 26, 2018
  5. Mischa POSLAWSKYOct 26, 2018
  6. Jeff KingOct 26, 2018
  7. Ævar Arnfjörð BjarmasonOct 26, 2018
  8. Rafael AscensãoOct 26, 2018
  9. Jason CooperOct 26, 2018
  10. Jason CooperOct 26, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.