dulwich-users team mailing list archive
-
dulwich-users team
-
Mailing list archive
-
Message #00390
[PATCH 2/7] repo: Allow recursive mkdir in Repo.init(_bare).
From: Dave Borowitz <dborowitz@xxxxxxxxxx>
Change-Id: I22b43e3ff6c9e2b8b127454126b28d8c5bc70cb0
---
dulwich/repo.py | 6 ++++--
dulwich/tests/test_repository.py | 26 ++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/dulwich/repo.py b/dulwich/repo.py
index 938252e..571932a 100644
--- a/dulwich/repo.py
+++ b/dulwich/repo.py
@@ -1202,14 +1202,16 @@ class Repo(BaseRepo):
@classmethod
def init(cls, path, mkdir=False):
if mkdir:
- os.mkdir(path)
+ os.makedirs(os.path.normpath(path))
controldir = os.path.join(path, ".git")
os.mkdir(controldir)
cls._init_maybe_bare(controldir, False)
return cls(path)
@classmethod
- def init_bare(cls, path):
+ def init_bare(cls, path, mkdir=False):
+ if mkdir:
+ os.makedirs(os.path.normpath(path))
return cls._init_maybe_bare(path, True)
create = init_bare
diff --git a/dulwich/tests/test_repository.py b/dulwich/tests/test_repository.py
index 1fb874b..7cf1cc9 100644
--- a/dulwich/tests/test_repository.py
+++ b/dulwich/tests/test_repository.py
@@ -90,6 +90,32 @@ class CreateRepositoryTests(TestCase):
self.assertEquals(os.path.join(self.tmp_dir, '.git'), repo._controldir)
self._check_repo_contents(repo, False)
+ def test_create_disk_bare_mkdir(self):
+ repo_dir = os.path.join(self.tmp_dir, 'foo.git')
+ repo = Repo.init_bare(repo_dir, mkdir=True)
+ self.assertEquals(repo_dir, repo._controldir)
+ self._check_repo_contents(repo, True)
+
+ def test_create_disk_non_bare_mkdir(self):
+ repo_dir = os.path.join(self.tmp_dir, 'foo')
+ repo = Repo.init(repo_dir, mkdir=True)
+ self.assertEquals(os.path.join(repo_dir, '.git'), repo._controldir)
+ self._check_repo_contents(repo, False)
+
+ def test_create_disk_bare_mkdir_recursive(self):
+ repo_dir = os.path.join(self.tmp_dir, 'foo', 'bar', 'baz.git')
+ repo = Repo.init_bare(repo_dir, mkdir=True)
+ self.assertEquals(repo_dir, repo._controldir)
+ self._check_repo_contents(repo, True)
+ self.assertRaises(OSError, Repo.init_bare, repo_dir, mkdir=True)
+
+ def test_create_disk_non_bare_mkdir_recursive(self):
+ repo_dir = os.path.join(self.tmp_dir, 'foo', 'bar', 'baz')
+ repo = Repo.init(repo_dir, mkdir=True)
+ self.assertEquals(os.path.join(repo_dir, '.git'), repo._controldir)
+ self._check_repo_contents(repo, False)
+ self.assertRaises(OSError, Repo.init, repo_dir, mkdir=True)
+
def test_create_memory(self):
repo = MemoryRepo.init_bare([], {})
self._check_repo_contents(repo, True)
--
1.7.3.2.168.gd6b63
References