kbjr/Git.php

Bare Repo Creation

Closed this issue · 3 comments

I can see the create_new() metthod creates a normal repo, but I guess creating a bare repo would make more sense.

Or at least have an alternative way to do that.

kbjr commented

You can run custom git commands with the run method, so the following should do what you want:

$repo = new GitRepo();
$repo->repo_path = '/path/to/repo/dir';
$repo->run('init --bare');

Obviously, circumventing the create/open methods and creating a GitRepo object manually like this isn't preferable, but it should get the job done.

Also, note: This assumes the repo path already exists. This will throw an error if the directory does not exist.

Edit: Sorry, just remembered that repo_path is a protected property, so you will have to either make it public in your copy of the code or add a method to the GitRepo class for assigning the repo_path value.

kbjr commented

Last update (hopefully):

I did some more looking at the source (haven't worked on this project in a while), and it looks like you can actually do it like this:

$repo = new GitRepo('/path/to/repo', true, false);
$repo->run('init --bare');

Let me know if you have any trouble getting this to work.

Thanks for the tips.

I actually mad "init --bare" the default behaviour.