1

I want to whitelist a couple of directories and a file:

/app
/config
/db
Gemfile

A go-to version control, git, does not allow to track a directory:

# .gitignore:
* # ignore all: suppose I prefer whitelisting
# but not the following things:
!/app/*
!/config/*
!/db/*
!Gemfile

Doesn't work: git only sees Gemfile.

Do you happen to know if any version control software allows to whitelist dirs and files?

Edit 1

Trying to apply https://stackoverflow.com/a/8025106/788700:

# Ignore everything:
*
# Don't ignore directories, so we can recurse into them:
!*/
# Don't ignore these dirs:
!app/*
!config/*
!db/*
# Don't ignore .gitignore and Gemfile:
!.gitignore
!Gemfile

— doesn't track dirs in app/, config/ and db/.

Edit 2: Solved

Using a comment from the above answer:

# Ignore everything:
*


# Don't ignore directories, so we can recurse into them:
!*/


# Don't ignore these dirs:
!app/*
!app/**/*

!config/*
!config/**/*

!db/*
!db/**/*


# Don't ignore .gitignore and Gemfile:
!.gitignore
!Gemfile

Seems to be working.

Community
  • 1
  • 1
Adobe
  • 12,967
  • 10
  • 85
  • 126
  • It's not clear, is this only a question about version control systems other than Git? (Your premise is incorrect; Git does allow you to do this, but you have to de-ignore the directory in which you _might_ have controlled files because Git doesn't descend into ignored directories even if you have subsequent patterns that might match files in those directories.) – CB Bailey Apr 28 '16 at 16:08
  • @CharlesBailey: yeap if one de-ignores all the dirs, including all child dirs, it works, but from my point of view it is not usable (because a list of child dirs will be changing a lot). I'm just looking for any solution which will allow to whitelist dirs "recursively". – Adobe Apr 28 '16 at 16:12
  • 2
    What is "whitelisting" in human terms? – Lazy Badger Apr 30 '16 at 15:40
  • Have you considered instead using a separate ignore file for each subdirectory? In [HG](https://www.selenic.com/mercurial/hgignore.5.html) you can use `subinclude:` for this. – Peter May 02 '16 at 09:31
  • @LazyBadger: by whitelisting I meant that some dirs are tracked recursively (including complete contents of these dirs). While all other files and dirs are ignored. So I can add `.passwords` file and be safe. This is opposed to traditional approach, where one would blacklist `.passwords` file to exclude it from tracking. – Adobe May 05 '16 at 08:08
  • 1
    http://stackoverflow.com/a/15329081/960558 http://stackoverflow.com/a/8025106/960558 - detect differences with your code – Lazy Badger May 05 '16 at 10:43

1 Answers1

2
  1. Git|Mercurial doesn't track empty directories, but if you'll add dummy-files in dirs - they will tracked (and successfully unignored)
  2. Git|Mercurial will apply ignore-patterns only for new files (not tracked), thus - if you'll ignore all, but add some objects by hand, they will be tracked regardless of *ignore-file setting (but see above)
  3. Subversion can track empty directories, but svn:ignore patterns are in common weaker, than equivalent mechanics in Git|Mercurial
Lazy Badger
  • 94,711
  • 9
  • 78
  • 110