matteosister / GitElephant

An abstraction layer for git written in PHP
GNU Lesser General Public License v3.0
613 stars 74 forks source link

prevent git from using wrong .git folder #92

Closed tolry closed 8 years ago

tolry commented 8 years ago

use case

my
|--folder
      |--workspace
               |--project
                      |--data

If I forgot to initialize the git repo under data and use GitElephant on that folder, git will automatically traverse upwards, until finding the first .git folder and will try to execute the commands on that repository.

I could not find an easy way fix this, since even when using the "-C" option, git still traverses upwards. One solution I could think of, would be to have Repository::open() validate, if the given folder actually contains a git repository, otherwise throwing an exception. In addition there would be an Repository::create()|init() method. This is obviously a BC break and might not be worth the hassle.

But since I fell into this trap just today, I wanted to at least report it :smile:

matteosister commented 8 years ago

Thanks for taking your time reporting this.

I don't think we should fix anything here. It is the expected git behavior, and trying to prevent this (I'm not aware of a way to do it) could cause confusion.

tolry commented 8 years ago

@matteosister It was a bit of a stretch, I know :smile: - bit is there a way with GitElephant to check, if a folder really is a repository (other than checking for a .git subfolder)? Currently I run Repository::init() each time, just to make sure. Since init can be called without risk multiple times.

Thanks for the quick reply, btw.

Great library, have enjoyed working with it so far!

matteosister commented 8 years ago

it could be easily done with a filesystem check, but I don't want to override any of the default behaviors of the git binary. You could do it in your code...but also doing a git init is fine imo.

matteosister commented 8 years ago

and thanks!!! :heart_eyes: