cookiecutter / cookiecutter-django

Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly.
https://cookiecutter-django.readthedocs.io
BSD 3-Clause "New" or "Revised" License
12.17k stars 2.91k forks source link

.envs/* exclusion in .gitignore may not be respected on Windows #3292

Closed chapb closed 2 years ago

chapb commented 3 years ago

What happened?

After working through "Getting Up and Running Locally With Docker", on a Windows machine, I ran git init, which triggered the addition of .env and .envs/* to .gitignore.

However, .envs/* was not ignored. Examining .gitignore, the two added lines are terminated with CR, whereas all other lines are terminated CRLF. As such, the ignore was not respected in this instance.

What should've happened instead?

.envs/* should be ignored, preventing production secrets from being exposed in source/version control. If I edit .gitignore manually and add line breaks, the ignore is respected.

Additional details

chapb commented 3 years ago

This function seems to be responsible for the addition to .gitignore.

https://github.com/pydanny/cookiecutter-django/blob/103cc9f2ffb594796b98b2916ecec043b8b5dd9e/hooks/post_gen_project.py#L130

Andrew-Chen-Wang commented 3 years ago

That's interesting. Could it be because of the mode we're in? We're using os.linesep which should work just fine...

ArtSphere commented 3 years ago

I have run into the same issue, not quite sure if I got it correctly, but in my mind it should actually have: ".envs/", instead of: ".envs/*" - as according to this from the Git Docu, it would ignore only direct childs of /envs directory otherwise, but have as an example the path ".envs/.production/.postgres" included:

The pattern "foo/*", matches "foo/test.json" (a regular file), "foo/bar" (a directory), but it does not match "foo/bar/hello.c" (a regular file), as the asterisk in the pattern does not match "bar/hello.c" which has a slash in it.

It did do the trick for me, to have the ".envs" directory ignored. I am having trouble to re-add the .local directory though - this entry appears not to work for me "!/.envs/.local"

Andrew-Chen-Wang commented 3 years ago

@ArtSphere maybe try clearing the git cache and re add the new line in the gitignore

browniebroke commented 2 years ago

This function seems to be responsible for the addition to .gitignore.

https://github.com/pydanny/cookiecutter-django/blob/103cc9f2ffb594796b98b2916ecec043b8b5dd9e/hooks/post_gen_project.py#L130

That's interesting... I'm wondering why we're doing that instead of the Jinja templating we do in the rest of the file. Has anyone tried it? That might fix it

browniebroke commented 2 years ago

That's interesting. Could it be because of the mode we're in? We're using os.linesep which should work just fine...

Looks like you're right! From the docs:

Do not use os.linesep as a line terminator when writing files opened in text mode (the default); use a single '\n' instead, on all platforms.