Permalink
Browse files

zomgawd basic clone!!

  • Loading branch information...
1 parent 1ec1fca commit e0c718d5db251629c2e3eee6d9d62c733b423d66 @samcday samcday committed Jun 1, 2012
Showing with 43 additions and 3 deletions.
  1. +3 −1 LIBGIT2_BUGS.md
  2. +26 −1 coffee/gitteh.coffee
  3. +11 −0 examples/clone.js
  4. +3 −1 src/remote.cc
View
@@ -1 +1,3 @@
-* Saving a commit with an unsaved tree segfaults.
+* Saving a commit with an unsaved tree segfaults.
+
+* calling git_remote_download without first calling git_remote_connect segfaults
View
@@ -1,4 +1,5 @@
{EventEmitter} = require "events"
+async = require "async"
args = require "./args"
bindings = require "../build/Debug/gitteh"
@@ -127,16 +128,20 @@ Gitteh.Remote = Remote = (@repository, nativeRemote) ->
connected = true
cb()
@fetch = =>
+ throw new Error "Remote isn't connected." if not connected
+
[cb] = args
cb: type: "function"
updateTimer = null
update = () ->
+ console.log "update."
console.log nativeRemote.stats
setTimeout update, 1000
setTimeout update, 1000
- nativeRemote.download
+ console.log "download()"
+ nativeRemote.download wrapCallback cb, -> nativeRemote.updateTips cb
return @
wrapCallback = (orig, cb) ->
@@ -213,3 +218,23 @@ Gitteh.initRepository = () ->
cb: type: "function"
bindings.initRepository path, bare, wrapCallback cb, (repo) ->
cb null, new Repository repo
+
+Gitteh.clone = =>
+ [url, path, cb] = args
+ url: type: "string"
+ path: type: "string"
+ cb: type: "function"
+ async.waterfall [
+ (cb) -> Gitteh.initRepository path, false, cb
+ (repo, cb) ->
+ repo.createRemote "origin", url, wrapCallback cb, (remote) ->
+ cb null, repo, remote
+ (repo, remote, cb) ->
+ remote.connect "fetch", wrapCallback cb, ->
+ cb null, repo, remote
+ (repo, remote, cb) ->
+ remote.fetch wrapCallback cb, ->
+ cb null, repo, remote
+ # TODO: checkout HEAD into working dir.
+ ], (err, repo) ->
+ console.log arguments
View
@@ -0,0 +1,11 @@
+var gitteh = require("../lib/gitteh");
+var path = require("path");
+var temp = require("temp");
+
+var repoPath = temp.mkdirSync();
+var repo = "http://github.com/libgit2/node-gitteh.git";
+
+console.log("Cloning " + repo + " into " + repoPath);
+gitteh.clone(repo, repoPath, function(err, repo) {
+ console.log(arguments);
+});
View
@@ -93,7 +93,7 @@ namespace gitteh {
NODE_SET_PROTOTYPE_METHOD(t, "updateTips", UpdateTips);
NODE_SET_PROTOTYPE_METHOD(t, "connect", Connect);
- NODE_SET_PROTOTYPE_METHOD(t, "download", Connect);
+ NODE_SET_PROTOTYPE_METHOD(t, "download", Download);
target->Set(class_symbol, constructor_template->GetFunction());
}
@@ -184,6 +184,7 @@ namespace gitteh {
Handle<Value> Remote::Download(const Arguments &args) {
HandleScope scope;
+ std::cout << "done." << std::endl;
Remote *remote = ObjectWrap::Unwrap<Remote>(args.This());
DownloadBaton *baton = new DownloadBaton(remote);
baton->setCallback(args[0]);
@@ -210,6 +211,7 @@ namespace gitteh {
void Remote::AsyncAfterDownload(uv_work_t *req) {
HandleScope scope;
+ std::cout<<"done."<<std::endl;
DownloadBaton *baton = GetBaton<DownloadBaton>(req);
baton->remote_->handle_->Delete(stats_symbol);

0 comments on commit e0c718d

Please sign in to comment.