From efb23767ca32361ef422b7bb8a5c2e206ae3b9be Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 2 Mar 2015 16:15:50 -0500 Subject: [PATCH 1/4] Convert Clone from object to function I find it really annoying that we have to do `NodeGit.Clone.clone` just to clone a repository. It would be much nicer to get a similar effect like in C, where you can run `git_clone`. This copies over the effect of an object, but actually using our `clone` patched function instead. I've made this commit first to show it does not introduce regressions with our current clone code. --- lib/clone.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/clone.js b/lib/clone.js index e6f51bf3c..e962ed563 100644 --- a/lib/clone.js +++ b/lib/clone.js @@ -45,4 +45,10 @@ Clone.clone = function(url, local_path, options) { .then(openRepository); }; -module.exports = Clone; +// Inherit directly from the original clone object. +Clone.clone.__proto__ = Clone; + +// Ensure we're using the correct prototype. +Clone.clone.prototype = Clone.prototype; + +module.exports = Clone.clone; From 5773320aa3d7596f15ae8bb6057151cb816a6d4d Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 2 Mar 2015 16:18:35 -0500 Subject: [PATCH 2/4] Test showing shorter clone syntax --- test/tests/clone.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/tests/clone.js b/test/tests/clone.js index e3634699e..b811c1420 100644 --- a/test/tests/clone.js +++ b/test/tests/clone.js @@ -4,9 +4,9 @@ var promisify = require("promisify-node"); var fse = promisify(require("fs-extra")); var local = path.join.bind(path, __dirname); -describe("Clone", function() { +describe.only("Clone", function() { var Repository = require(local("../../lib/repository")); - var Clone = require(local("../../lib/clone")); + var clone = require(local("../../lib/clone")); var NodeGit = require(local("../../")); var clonePath = local("../repos/clone"); @@ -29,7 +29,7 @@ describe("Clone", function() { var test = this; var url = "http://git.tbranyen.com/smart/site-content"; - return Clone.clone(url, clonePath).then(function(repo) { + return clone(url, clonePath).then(function(repo) { assert.ok(repo instanceof Repository); test.repository = repo; }); @@ -46,7 +46,7 @@ describe("Clone", function() { } }; - return Clone.clone(url, clonePath, opts).then(function(repo) { + return clone(url, clonePath, opts).then(function(repo) { assert.ok(repo instanceof Repository); test.repository = repo; }); @@ -66,7 +66,7 @@ describe("Clone", function() { } }; - return Clone.clone(url, clonePath, opts).then(function(repo) { + return clone(url, clonePath, opts).then(function(repo) { assert.ok(repo instanceof Repository); test.repository = repo; }); @@ -90,7 +90,7 @@ describe("Clone", function() { } }; - return Clone.clone(url, clonePath, opts).then(function(repo) { + return clone(url, clonePath, opts).then(function(repo) { assert.ok(repo instanceof Repository); test.repository = repo; }); @@ -107,7 +107,7 @@ describe("Clone", function() { } }; - return Clone.clone(url, clonePath, opts).then(function(repo) { + return clone(url, clonePath, opts).then(function(repo) { test.repository = repo; assert.ok(repo instanceof Repository); }); @@ -118,7 +118,7 @@ describe("Clone", function() { var prefix = process.platform === "win32" ? "" : "file://"; var url = prefix + local("../repos/empty"); - return Clone.clone(url, clonePath).then(function(repo) { + return clone(url, clonePath).then(function(repo) { assert.ok(repo instanceof Repository); test.repository = repo; }); @@ -127,7 +127,7 @@ describe("Clone", function() { it("will not segfault when accessing a url without username", function() { var url = "https://github.com/nodegit/private"; - return Clone.clone(url, clonePath, { + return clone(url, clonePath, { remoteCallbacks: { certificateCheck: function() { return 1; From 7061d68484fc937202373040c4b9d8239fc6cf91 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 2 Mar 2015 16:19:42 -0500 Subject: [PATCH 3/4] Updated examples to show new syntax --- examples/clone.js | 2 +- examples/cloneFromGithubWith2Factor.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/clone.js b/examples/clone.js index d4c481490..b01ab99ab 100644 --- a/examples/clone.js +++ b/examples/clone.js @@ -6,7 +6,7 @@ var path = "/tmp/nodegit-clone-demo"; fse.remove(path).then(function() { var entry; - nodegit.Clone.clone( + nodegit.Clone( "https://github.com/nodegit/nodegit.git", path, { diff --git a/examples/cloneFromGithubWith2Factor.js b/examples/cloneFromGithubWith2Factor.js index 3e2186d3c..8c8ca0829 100644 --- a/examples/cloneFromGithubWith2Factor.js +++ b/examples/cloneFromGithubWith2Factor.js @@ -36,7 +36,7 @@ var opts = { }; fse.remove(path).then(function() { - nodegit.Clone.clone(repoUrl, path, opts) + nodegit.Clone(repoUrl, path, opts) .done(function(repo) { if (repo instanceof nodegit.Repository) { console.info("We cloned the repo!"); From 4c888f5a017b16128a6b255561d8bb48e459a3db Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 2 Mar 2015 17:25:41 -0500 Subject: [PATCH 4/4] Remove only from describe block --- test/tests/clone.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tests/clone.js b/test/tests/clone.js index b811c1420..a75692335 100644 --- a/test/tests/clone.js +++ b/test/tests/clone.js @@ -4,7 +4,7 @@ var promisify = require("promisify-node"); var fse = promisify(require("fs-extra")); var local = path.join.bind(path, __dirname); -describe.only("Clone", function() { +describe("Clone", function() { var Repository = require(local("../../lib/repository")); var clone = require(local("../../lib/clone")); var NodeGit = require(local("../../"));