Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for directory-only negation #36

Merged
merged 1 commit into from
Nov 20, 2022

Conversation

szczeles
Copy link
Contributor

While integrating your library I found one case that is a mismatch with how .gitignore works. It relates to support of directory-only negation - useful thing when you want to discard some spool dir, but keep the directory structure in the version control. The feature is used by Kedro framework in their proejct template:

# ignore everything in the following folders
data/**
# except their sub-folders
!data/**/
# also keep all .gitkeep files
!.gitkeep

and makes it easy to store the structure of data/ subdirs in git:

$ tree -a data/
data/
├── 01_raw
│   └── .gitkeep
├── 02_intermediate
│   └── .gitkeep
├── 03_primary
│   └── .gitkeep
├── 04_features
│   └── .gitkeep
├── 05_model_input
│   └── .gitkeep
├── 06_models
│   └── .gitkeep
└── 08_reporting
    └── .gitkeep

7 directories, 7 files

This PR fixes the directory-only-negation support, together with a small test. You can also verify the behaviour with pure git:

$ cat > .gitignore <<EOF
> data/**
> !data/**/
> !.gitkeep
> !data/01_raw/*
> EOF
$ git init
$ mkdir -p data/01_raw/
$ touch data/01_raw/.gitkeep
$ touch data/01_raw/data.csv
$ mkdir -p data/02_processed/
$ touch data/02_processed/.gitkeep
$ touch data/02_processed/data.csv
$ git add -A
$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
	new file:   .gitignore
	new file:   data/01_raw/.gitkeep
	new file:   data/01_raw/data.csv
	new file:   data/02_processed/.gitkeep

If you're OK with my modifications, I would be glad if you can release it as a new version of pypi, so I can integrate non-fork version in my project. Thanks :-)

@mherrmann mherrmann merged commit 997faee into mherrmann:master Nov 20, 2022
@mherrmann
Copy link
Owner

mherrmann commented Nov 20, 2022

Thanks! Merged and published to PyPI as v0.1.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants