GitRepository.clone(): add depth and recursive parameter
authorGuido Günther <agx@sigxcpu.org>
Mon, 24 Oct 2011 14:10:47 +0000 (16:10 +0200)
committerGuido Günther <agx@sigxcpu.org>
Wed, 26 Oct 2011 07:45:10 +0000 (09:45 +0200)
gbp/git.py

index d049f15..a7b5fba 100644 (file)
@@ -929,7 +929,7 @@ class GitRepository(object):
         return None
 
     @classmethod
-    def clone(klass, path, remote):
+    def clone(klass, path, remote, depth=0, recursive=False):
         """
         Clone a git repository at I{path}
 
@@ -937,15 +937,21 @@ class GitRepository(object):
         @type path: string
         @param remote: URL to clone
         @type remote: string
+        @param depth: create a shallow clone of depth I{depth}
+        @type depth: int
+        @param recursive: whether to clone submodules
+        @type recursive: bool
         @return: git repository object
         @rtype:GitRepository
         """
         abspath = os.path.abspath(path)
+        args = [ '--depth', depth ] if depth else []
+        args += [ '--recursive' ] if recursive else []
         try:
             if not os.path.exists(abspath):
                 os.makedirs(abspath)
 
-            GitCommand("clone", [remote], cwd=abspath)()
+            GitCommand("clone", args + [remote], cwd=abspath)()
             (clone, dummy) = os.path.splitext(remote.rstrip('/').rsplit('/',1)[1])
             return klass(os.path.join(abspath, clone))
         except OSError, err: