Pārlūkot izejas kodu

Add checkout argument to clone. Fixes #503

Jelmer Vernooij 7 gadi atpakaļ
vecāks
revīzija
f83a70b8a7
4 mainītis faili ar 24 papildinājumiem un 2 dzēšanām
  1. 3 0
      NEWS
  2. 1 0
      dulwich/porcelain.py
  3. 6 2
      dulwich/repo.py
  4. 14 0
      dulwich/tests/test_repository.py

+ 3 - 0
NEWS

@@ -8,6 +8,9 @@
   * When the `DULWICH_PDB` environment variable is set, make
     SIGQUIT open pdb in the 'dulwich' command.
 
+  * Add `checkout` argument to `Repo.clone`.
+    (Jelmer Vernooij, #503)
+
  BUG FIXES
 
   * Fix handling of encoding for tags. (Jelmer Vernooij, #608)

+ 1 - 0
dulwich/porcelain.py

@@ -292,6 +292,7 @@ def clone(source, target=None, bare=False, checkout=None,
     :param origin: Name of remote from the repository used to clone
     :return: The new repository
     """
+    # TODO(jelmer): This code overlaps quite a bit with Repo.clone
     if outstream is not None:
         import warnings
         warnings.warn(

+ 6 - 2
dulwich/repo.py

@@ -974,7 +974,7 @@ class Repo(BaseRepo):
         index.write()
 
     def clone(self, target_path, mkdir=True, bare=False,
-              origin=b"origin"):
+              origin=b"origin", checkout=None):
         """Clone this repository.
 
         :param target_path: Target path
@@ -987,6 +987,8 @@ class Repo(BaseRepo):
         if not bare:
             target = self.init(target_path, mkdir=mkdir)
         else:
+            if checkout:
+                raise ValueError("checkout and bare are incompatible")
             target = self.init_bare(target_path, mkdir=mkdir)
         self.fetch(target)
         encoded_path = self.path
@@ -1018,7 +1020,9 @@ class Repo(BaseRepo):
                                          message=ref_message)
             target[b'HEAD'] = head_sha
 
-            if not bare:
+            if checkout is None:
+                checkout = (not bare)
+            if checkout:
                 # Checkout HEAD to target dir
                 target.reset_index()
 

+ 14 - 0
dulwich/tests/test_repository.py

@@ -325,6 +325,20 @@ class RepositoryRootTests(TestCase):
         self.addCleanup(shutil.rmtree, tmp_dir)
         r.clone(tmp_dir, mkdir=False, bare=True)
 
+    def test_clone_bare(self):
+        r = self.open_repo('a.git')
+        tmp_dir = self.mkdtemp()
+        self.addCleanup(shutil.rmtree, tmp_dir)
+        t = r.clone(tmp_dir, mkdir=False)
+        t.close()
+
+    def test_clone_checkout_and_bare(self):
+        r = self.open_repo('a.git')
+        tmp_dir = self.mkdtemp()
+        self.addCleanup(shutil.rmtree, tmp_dir)
+        self.assertRaises(ValueError, r.clone, tmp_dir, mkdir=False,
+                          checkout=True, bare=True)
+
     def test_merge_history(self):
         r = self.open_repo('simple_merge.git')
         shas = [e.commit.id for e in r.get_walker()]