git/GitRepository.st
changeset 11 07cb27974501
parent 10 3d98ee6c5c64
child 12 59d59fc32b71
--- a/git/GitRepository.st	Wed Sep 19 13:18:31 2012 +0000
+++ b/git/GitRepository.st	Wed Sep 19 14:47:53 2012 +0000
@@ -10,6 +10,32 @@
 
 !GitRepository class methodsFor:'instance creation'!
 
+clone: url to: stringOrDirectory
+    | dir ref fetchStats checkoutStats |
+
+    dir := stringOrDirectory asFilename.
+    dir exists ifTrue:[
+        GitError raiseErrorString:'Destination directory already exists'.
+        ^self
+    ].
+    dir directory isDirectory ifFalse:[
+        GitError raiseErrorString:'Parent directory for destination does not exists'.
+        ^self
+    ].
+
+    ref := ByteArray new: ExternalBytes sizeofPointer.
+    fetchStats := GitIndexerStatsStructure new.
+    checkoutStats := GitIndexerStatsStructure new.
+    GitError raiseIfError: 
+        (GitPrimitives prim_git_clone: ref origin_url: url asString workdir_path: dir pathName fetch_stats: fetchStats checkout_stats: checkoutStats checkout_opts: ExternalAddress new).
+    ^self new 
+        setHandleFromRef:ref;
+        setPath: dir pathName;
+        yourself
+
+    "Created: / 19-09-2012 / 15:27:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 open: aString
     "Opens an existing git repository on given path"
 
@@ -35,6 +61,15 @@
 
 !GitRepository methodsFor:'accessing'!
 
+workingCopy
+    self isBare ifTrue:[
+        GitError raiseErrorString: 'Repository is bare'.
+    ].
+    ^GitWorkingCopy new setRepository: self
+
+    "Created: / 19-09-2012 / 15:32:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 workingCopyOn: aStringOrFilename
     | repo directory |