Closed deizel closed 9 years ago
I'd like to discuss the behavior here a bit.
If .gitignore
file is already present, it's safe to assuming that the consuming project is using git, and thus we should be helpful and add the necessary entries. So far, so good.
However, if no .gitignore is present, the consuming project may be using git, or they could be using Mercurial or Subversion or nothing at all. While I'm content not adding support for exclusion mechanisms used by other version control systems until there is a demand for them, I'm not sure we should presume to add a potentially unnecessary .gitignore file to the consuming project.
There are a few solutions I can think of:
.gitignore
even if there wasn't one..gitignore
, and only make the additions if the file is present already. This has the downside of missing a case where the consuming project is using git but hasn't had a need for a .gitignore
file yet (which seems unlikely based only on my own person experience, but nevertheless, a risk.).git/
folder to determine whether to create/update the .gitignore
file. This option seems the most reliable to me, but I'm definitely open to feedback.In any case, it's clear that the try/catch
block that was intended to already handle the case of a missing .gitignore file is not sufficient, since file()
seems to throw an error instead of an exception. I think no matter what we need to clean that up.
Does anybody have any thoughts they'd like to contribute?
I'm in favor of option 3:
.git/
folder to determine whether to create/update the .gitignore
file.I'm inclined to agree. What do you think, @deizel? Would you be willing to rework your PR? Otherwise we can close this one and handle the change ourselves. Either way we're grateful for you putting some attention towards this.
Sounds like a plan - I've modified the PR to check for a .git/
directory before proceeding.
Note that Git is afraid of .git/
, so I've modified the test script to create the directory instead:
$ git add .git/empty
error: Invalid path 'tests/integration/.git/empty'
error: unable to add tests/integration/.git/empty to index
fatal: adding files failed
If you think there are any improvements to make before merging let me know.
Looks pretty nice to me. Thank you!
No problem. :smile:
Found this during my testing, a nice big red error if the consuming project doesn't have a
.gitignore
file.Using PHP's
touch()
prevents this error from occurring.