From 0651f0964ba5a33257ebbda1e92c7a1649a4a058 Mon Sep 17 00:00:00 2001 From: Michael Trier Date: Sun, 18 May 2008 10:55:31 -0400 Subject: lots of little fixes. Corrected problem with creating bare repo. Added Repo.create alias. --- lib/git_python/repo.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'lib/git_python/repo.py') diff --git a/lib/git_python/repo.py b/lib/git_python/repo.py index f04ba19c..dc9fa729 100644 --- a/lib/git_python/repo.py +++ b/lib/git_python/repo.py @@ -250,13 +250,17 @@ class Repo(object): return Commit.diff(self, commit) @classmethod - def init_bare(self, path, **kwargs): + def init_bare(self, path, mkdir=True, **kwargs): """ Initialize a bare git repository at the given path ``path`` is the full path to the repo (traditionally ends with /.git) + ``mkdir`` + if specified will create the repository directory if it doesn't + already exists. Creates the directory with a mode=0755. + ``kwargs`` is any additional options to the git init command @@ -267,9 +271,19 @@ class Repo(object): Returns ``GitPython.Repo`` (the newly created repo) """ - git = Git(path) - git.init(**kwargs) + split = os.path.split(path) + if split[-1] == '.git' or os.path.split(split[0])[-1] == '.git': + gitpath = path + else: + gitpath = os.path.join(path, '.git') + + if mkdir and not os.path.exists(gitpath): + os.makedirs(gitpath, 0755) + + git = Git(gitpath) + output = git.init(**kwargs) return Repo(path) + create = init_bare def fork_bare(self, path, **kwargs): """ @@ -284,7 +298,7 @@ class Repo(object): Returns ``GitPython.Repo`` (the newly forked repo) """ - options = {'bare': True, 'shared': False} + options = {'bare': True} options.update(kwargs) self.git.clone(self.path, path, **options) return Repo(path) -- cgit v1.2.1