Browse Source

Pass 'mkdir' argument onto Repo.init_bare() from Repo.clone. Fixes #504

Jelmer Vernooij 7 years ago
parent
commit
2f2ae37b07
3 changed files with 23 additions and 2 deletions
  1. 3 0
      NEWS
  2. 4 2
      dulwich/repo.py
  3. 16 0
      dulwich/tests/test_repository.py

+ 3 - 0
NEWS

@@ -7,6 +7,9 @@
   * Fix build of C extensions with Python 3 on Windows.
     (Jelmer Vernooij)
 
+  * Pass 'mkdir' argument onto Repo.init_bare in Repo.clone.
+    (Jelmer Vernooij, #504)
+
  DOCUMENTATION
 
   * Clarified docstrings for Client.{send_pack,fetch_pack} implementations.

+ 4 - 2
dulwich/repo.py

@@ -888,7 +888,7 @@ class Repo(BaseRepo):
         if not bare:
             target = self.init(target_path, mkdir=mkdir)
         else:
-            target = self.init_bare(target_path)
+            target = self.init_bare(target_path, mkdir=mkdir)
         self.fetch(target)
         target.refs.import_refs(
             b'refs/remotes/' + origin, self.refs.as_dict(b'refs/heads'))
@@ -1052,7 +1052,7 @@ class Repo(BaseRepo):
         return r
 
     @classmethod
-    def init_bare(cls, path):
+    def init_bare(cls, path, mkdir=False):
         """Create a new bare repository.
 
         ``path`` should already exist and be an empty directory.
@@ -1060,6 +1060,8 @@ class Repo(BaseRepo):
         :param path: Path to create bare repository in
         :return: a `Repo` instance
         """
+        if mkdir:
+            os.mkdir(path)
         return cls._init_maybe_bare(path, True)
 
     create = init_bare

+ 16 - 0
dulwich/tests/test_repository.py

@@ -98,6 +98,22 @@ class CreateRepositoryTests(TestCase):
         self.assertEqual(os.path.join(tmp_dir, '.git'), repo._controldir)
         self._check_repo_contents(repo, False)
 
+    def test_create_disk_non_bare_mkdir(self):
+        tmp_dir = tempfile.mkdtemp()
+        target_dir = os.path.join(tmp_dir, "target")
+        self.addCleanup(shutil.rmtree, tmp_dir)
+        repo = Repo.init(target_dir, mkdir=True)
+        self.assertEqual(os.path.join(target_dir, '.git'), repo._controldir)
+        self._check_repo_contents(repo, False)
+
+    def test_create_disk_bare_mkdir(self):
+        tmp_dir = tempfile.mkdtemp()
+        target_dir = os.path.join(tmp_dir, "target")
+        self.addCleanup(shutil.rmtree, tmp_dir)
+        repo = Repo.init_bare(target_dir, mkdir=True)
+        self.assertEqual(target_dir, repo._controldir)
+        self._check_repo_contents(repo, True)
+
 
 class MemoryRepoTests(TestCase):