-1

git here.

My project structure will look something like this:

app/
    README.md
    .gitignore
    src/
        <all source code goes here>
    docs/
        <docs go here>
    misc/
        examples/
            <examples go here>
        fizzbuzz/
            properties/
            configs/

The misc/fizzbuzz/properties/ directory is very special and I am hoping to be able to set up some special .gitignore configurations for it. In this directory I will have many child directories, like so:

app/
    README.md
    .gitignore
    src/
        <all source code goes here>
    docs/
        <docs go here>
    misc/
        examples/
            <examples go here>
        fizzbuzz/
            properties/
                abc/
                def/
                ghi/
                ...etc.
            configs/

Each of these child directories (of properties/) will follow the same pattern:

abc/
    abc.properties
    abc.txt
    many many other files...
def/
    def.properties
    def.txt
    many many other files...
ghi/
    ghi.properties
    ghi.txt
    many many other files...

So in each child directory there will be:

  1. A properties file whose name is the exact same as the name of the child directory it is a member of (ghi.properties under properties/ghi/, etc.); and
  2. A txt file whose name is also the exact same as the name of the child directory it is a member of (ghi.txt under properties/ghi/, etc.); and
  3. Many, many other files. Some will be ghi.* (a "ghi" file, just not of type properties or txt). Some will be *.properties or *.txt (other properties files or txt files, just not ghi.properties or ghi.txt, etc.). Some will be named all over the place (foobar.mp4, flam.csv, etc.). But the thing these files have in common is that they are not of the form "<parent-dir-name>.properties" or "<parent-dir-name>.txt".

I am trying to configure .gitignore to ignore everything in these child directories except for the properties and txt file that matches the name of the directory they live inside of.

Can anyone help nudge me in the right direction?

simplezarg
  • 168
  • 1
  • 9
  • 1
    I do not understand. So just create one .gitignore by hand and be done with it. If this is super dynamic, write a script to generate your .gitignore every time files change. What specific problem are you struggling with? `nudge me in the right direction?` You know the list of requirements. Research .gitignore syntax, read the documentation, and write the file and continue your work. – KamilCuk Mar 01 '22 at 08:18
  • I mean you could make the same argument for any question on this site. Know your requirements, read the manual and implement the solution. Except of course, that response is ridiculous on a help-based Q&A platform. – simplezarg Mar 01 '22 at 13:10
  • `you could make` Yes, I can, many times I do. I am sorry, no, I hope it isn't ridiculous. When answering questions on this site, I feel overwhelmed by people not even trying to read the documentation. Here https://stackoverflow.com/questions/987142/make-gitignore-ignore-everything-except-a-few-files you can learn how to ignore all files except a few. And, to apply that to multiple directories, write such gitignore by hand or write a script in your favorite programming language to generate such .gitignore file . There are no loop or I/O utilities in .gitignore, it's a simple line-based file. – KamilCuk Mar 01 '22 at 13:24
  • However, I recommend [ask] , https://stackoverflow.com/help/on-topic and https://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist and https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users . The question `Can anyone help nudge me in the right direction?` is too vague for this site - this site for specific programming questions. As you do not ask a _specific programming_ question in my opinion, and ask about "direction", I recommended researching the documentation. I hope this recommendation is a valid approach. – KamilCuk Mar 01 '22 at 13:28

1 Answers1

1

Composing a simple .gitignore file by hand seems simple:

abc
!abc/abc.properties
!abc/abc.txt
def
!def/def.properties
!def/def.txt
# ...etc.

A short Bash shell script to generate such .gitignore file could look like this, but a more readable version with basename would maybe be clearer:

cd app/...../properties
for i in */; do printf "%s\n" "${i%/}" '!'"$i${i%/}."{properties,txt}; done > .gitignore

Such a script could be added to git-commit hooks or to the automation that generates the folders.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111