@@ -250,13 +250,17 @@ def commit_diff(self, commit):
250250 return Commit .diff (self , commit )
251251
252252 @classmethod
253- def init_bare (self , path , ** kwargs ):
253+ def init_bare (self , path , mkdir = True , ** kwargs ):
254254 """
255255 Initialize a bare git repository at the given path
256256
257257 ``path``
258258 is the full path to the repo (traditionally ends with /<name>.git)
259259
260+ ``mkdir``
261+ if specified will create the repository directory if it doesn't
262+ already exists. Creates the directory with a mode=0755.
263+
260264 ``kwargs``
261265 is any additional options to the git init command
262266
@@ -267,9 +271,19 @@ def init_bare(self, path, **kwargs):
267271 Returns
268272 ``GitPython.Repo`` (the newly created repo)
269273 """
270- git = Git (path )
271- git .init (** kwargs )
274+ split = os .path .split (path )
275+ if split [- 1 ] == '.git' or os .path .split (split [0 ])[- 1 ] == '.git' :
276+ gitpath = path
277+ else :
278+ gitpath = os .path .join (path , '.git' )
279+
280+ if mkdir and not os .path .exists (gitpath ):
281+ os .makedirs (gitpath , 0755 )
282+
283+ git = Git (gitpath )
284+ output = git .init (** kwargs )
272285 return Repo (path )
286+ create = init_bare
273287
274288 def fork_bare (self , path , ** kwargs ):
275289 """
@@ -284,7 +298,7 @@ def fork_bare(self, path, **kwargs):
284298 Returns
285299 ``GitPython.Repo`` (the newly forked repo)
286300 """
287- options = {'bare' : True , 'shared' : False }
301+ options = {'bare' : True }
288302 options .update (kwargs )
289303 self .git .clone (self .path , path , ** options )
290304 return Repo (path )
0 commit comments