@@ -606,26 +606,15 @@ def init(cls, path=None, mkdir=True, **kwargs):
606
606
output = git .init (** kwargs )
607
607
return Repo (path )
608
608
609
- def clone (self , path , ** kwargs ):
610
- """Create a clone from this repository.
611
- :param path:
612
- is the full path of the new repo (traditionally ends with ./<name>.git).
613
-
614
- :param kwargs:
615
- odbt = ObjectDatabase Type, allowing to determine the object database
616
- implementation used by the returned Repo instance
617
-
618
- All remaining keyword arguments are given to the git-clone command
619
-
620
- :return:
621
- ``git.Repo`` (the newly cloned repo)"""
609
+ @classmethod
610
+ def _clone (cls , git , url , path , odb_default_type , ** kwargs ):
622
611
# special handling for windows for path at which the clone should be
623
612
# created.
624
613
# tilde '~' will be expanded to the HOME no matter where the ~ occours. Hence
625
614
# we at least give a proper error instead of letting git fail
626
615
prev_cwd = None
627
616
prev_path = None
628
- odbt = kwargs .pop ('odbt' , type ( self . odb ) )
617
+ odbt = kwargs .pop ('odbt' , odb_default_type )
629
618
if os .name == 'nt' :
630
619
if '~' in path :
631
620
raise OSError ("Git cannot handle the ~ character in path %r correctly" % path )
@@ -645,7 +634,7 @@ def clone(self, path, **kwargs):
645
634
# END windows handling
646
635
647
636
try :
648
- self . git .clone (self . git_dir , path , ** kwargs )
637
+ git .clone (url , path , ** kwargs )
649
638
finally :
650
639
if prev_cwd is not None :
651
640
os .chdir (prev_cwd )
@@ -655,10 +644,32 @@ def clone(self, path, **kwargs):
655
644
656
645
# our git command could have a different working dir than our actual
657
646
# environment, hence we prepend its working dir if required
658
- if not os .path .isabs (path ) and self . git .working_dir :
659
- path = join (self . git ._working_dir , path )
660
- return Repo (os .path .abspath (path ), odbt = odbt )
647
+ if not os .path .isabs (path ) and git .working_dir :
648
+ path = join (git ._working_dir , path )
649
+ return cls (os .path .abspath (path ), odbt = odbt )
661
650
651
+ def clone (self , path , ** kwargs ):
652
+ """Create a clone from this repository.
653
+ :param path:
654
+ is the full path of the new repo (traditionally ends with ./<name>.git).
655
+
656
+ :param kwargs:
657
+ odbt = ObjectDatabase Type, allowing to determine the object database
658
+ implementation used by the returned Repo instance
659
+
660
+ All remaining keyword arguments are given to the git-clone command
661
+
662
+ :return: ``git.Repo`` (the newly cloned repo)"""
663
+ return self ._clone (self .git , self .git_dir , path , type (self .odb ), ** kwargs )
664
+
665
+ @classmethod
666
+ def clone_from (cls , url , to_path , ** kwargs ):
667
+ """Create a clone from the given URL
668
+ :param url: valid git url, see http://www.kernel.org/pub/software/scm/git/docs/git-clone.html#URLS
669
+ :param to_path: Path to which the repository should be cloned to
670
+ :param **kwargs: see the ``clone`` method
671
+ :return: Repo instance pointing to the cloned directory"""
672
+ return cls ._clone (Git (os .getcwd ()), url , to_path , GitCmdObjectDB , ** kwargs )
662
673
663
674
def archive (self , ostream , treeish = None , prefix = None , ** kwargs ):
664
675
"""Archive the tree at the given revision.
0 commit comments