@@ -250,13 +250,17 @@ def commit_diff(self, commit):
250
250
return Commit .diff (self , commit )
251
251
252
252
@classmethod
253
- def init_bare (self , path , ** kwargs ):
253
+ def init_bare (self , path , mkdir = True , ** kwargs ):
254
254
"""
255
255
Initialize a bare git repository at the given path
256
256
257
257
``path``
258
258
is the full path to the repo (traditionally ends with /<name>.git)
259
259
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
+
260
264
``kwargs``
261
265
is any additional options to the git init command
262
266
@@ -267,9 +271,19 @@ def init_bare(self, path, **kwargs):
267
271
Returns
268
272
``GitPython.Repo`` (the newly created repo)
269
273
"""
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 )
272
285
return Repo (path )
286
+ create = init_bare
273
287
274
288
def fork_bare (self , path , ** kwargs ):
275
289
"""
@@ -284,7 +298,7 @@ def fork_bare(self, path, **kwargs):
284
298
Returns
285
299
``GitPython.Repo`` (the newly forked repo)
286
300
"""
287
- options = {'bare' : True , 'shared' : False }
301
+ options = {'bare' : True }
288
302
options .update (kwargs )
289
303
self .git .clone (self .path , path , ** options )
290
304
return Repo (path )
0 commit comments