From 749826c81799fc5b00a0ed4a18d98e67f27f1eaa Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Tue, 24 Feb 2015 16:14:20 -0800 Subject: [PATCH 01/12] Attempt to fix Windows file locking bug --- generate/input/descriptor.json | 3 --- generate/scripts/helpers.js | 4 ++-- test/tests/clone.js | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index 768a9b5a6..6c4da260c 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -1431,9 +1431,6 @@ "git_repository_fetchhead_foreach": { "ignore": true }, - "git_repository_free": { - "ignore": true - }, "git_repository_hashfile": { "ignore": true }, diff --git a/generate/scripts/helpers.js b/generate/scripts/helpers.js index 49cf3be44..733e546a6 100644 --- a/generate/scripts/helpers.js +++ b/generate/scripts/helpers.js @@ -288,8 +288,8 @@ var Helpers = { // available if (key == typeDef.cType + "_free") { typeDef.freeFunctionName = key; - fnDef.ignore = true; - return; + //fnDef.ignore = true; + //return; } fnDef.cppFunctionName = Helpers.cTypeToCppName(key, "git_" + typeDef.typeName); diff --git a/test/tests/clone.js b/test/tests/clone.js index 6f485672e..987e25687 100644 --- a/test/tests/clone.js +++ b/test/tests/clone.js @@ -28,7 +28,9 @@ describe("Clone", function() { fse.remove(ssh), fse.remove(git), fse.remove(file) - ]).catch(function unhandledFunction() {}); + ]).catch(function unhandledFunction(ex) { + console.log(ex.message); + }); }); it.skip("can clone with http", function() { @@ -43,6 +45,7 @@ describe("Clone", function() { return Clone.clone(url, http, opts).then(function(repo) { assert.ok(repo instanceof Repository); + repo.free(); }); }); @@ -58,6 +61,8 @@ describe("Clone", function() { return Clone.clone(url, https, opts).then(function(repo) { assert.ok(repo instanceof Repository); + repo.stateCleanup(); + repo.free(); }); }); @@ -76,6 +81,8 @@ describe("Clone", function() { return Clone.clone(url, ssh, opts).then(function(repo) { assert.ok(repo instanceof Repository); + repo.stateCleanup(); + repo.free(); }); }); @@ -98,6 +105,8 @@ describe("Clone", function() { return Clone.clone(url, ssh, opts).then(function(repo) { assert.ok(repo instanceof Repository); + repo.stateCleanup(); + repo.free(); }); }); @@ -113,6 +122,8 @@ describe("Clone", function() { return Clone.clone(url, git, opts).then(function(repo) { assert.ok(repo instanceof Repository); + repo.stateCleanup(); + repo.free(); }); }); @@ -122,6 +133,8 @@ describe("Clone", function() { return Clone.clone(url, file).then(function(repo) { assert.ok(repo instanceof Repository); + repo.stateCleanup(); + repo.free(); }); }); From aea1ae7e139b24bcec38de33b11d53155709e1b8 Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Tue, 24 Feb 2015 17:28:30 -0800 Subject: [PATCH 02/12] Change to a single clone path --- test/tests/clone.js | 61 ++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/test/tests/clone.js b/test/tests/clone.js index 987e25687..0fdd344f0 100644 --- a/test/tests/clone.js +++ b/test/tests/clone.js @@ -9,11 +9,7 @@ describe("Clone", function() { var Clone = require(local("../../lib/clone")); var NodeGit = require(local("../../")); - var http = local("../repos/http"); - var https = local("../repos/https"); - var ssh = local("../repos/ssh"); - var git = local("../repos/git"); - var file = local("../repos/file"); + var clonePath = local("../repos/clone"); var sshPublicKey = local("../id_rsa.pub"); var sshPrivateKey = local("../id_rsa"); @@ -22,18 +18,23 @@ describe("Clone", function() { this.timeout(30000); beforeEach(function() { - return NodeGit.Promise.all([ - fse.remove(http), - fse.remove(https), - fse.remove(ssh), - fse.remove(git), - fse.remove(file) - ]).catch(function unhandledFunction(ex) { - console.log(ex.message); + return fse.remove(clonePath); + }); + + afterEach(function(done) { + if (this.repository) { + this.repository.free(); + delete this.repository; + } + + process.nextTick(function() { + gc(); + done(); }); }); it.skip("can clone with http", function() { + var test = this; var url = "http://github.com/nodegit/test.git"; var opts = { remoteCallbacks: { @@ -43,13 +44,14 @@ describe("Clone", function() { } }; - return Clone.clone(url, http, opts).then(function(repo) { + return Clone.clone(url, clonePath, opts).then(function(repo) { assert.ok(repo instanceof Repository); - repo.free(); + test.repository = repo; }); }); it("can clone with https", function() { + var test = this; var url = "https://github.com/nodegit/test.git"; var opts = { remoteCallbacks: { @@ -59,14 +61,14 @@ describe("Clone", function() { } }; - return Clone.clone(url, https, opts).then(function(repo) { + return Clone.clone(url, clonePath, opts).then(function(repo) { assert.ok(repo instanceof Repository); - repo.stateCleanup(); - repo.free(); + test.repository = repo; }); }); it("can clone with ssh", function() { + var test = this; var url = "git@github.com:nodegit/test.git"; var opts = { remoteCallbacks: { @@ -79,14 +81,14 @@ describe("Clone", function() { } }; - return Clone.clone(url, ssh, opts).then(function(repo) { + return Clone.clone(url, clonePath, opts).then(function(repo) { assert.ok(repo instanceof Repository); - repo.stateCleanup(); - repo.free(); + test.repository = repo; }); }); it("can clone with ssh while manually loading a key", function() { + var test = this; var url = "git@github.com:nodegit/test.git"; var opts = { remoteCallbacks: { @@ -103,10 +105,9 @@ describe("Clone", function() { } }; - return Clone.clone(url, ssh, opts).then(function(repo) { + return Clone.clone(url, clonePath, opts).then(function(repo) { assert.ok(repo instanceof Repository); - repo.stateCleanup(); - repo.free(); + test.repository = repo; }); }); @@ -120,28 +121,26 @@ describe("Clone", function() { } }; - return Clone.clone(url, git, opts).then(function(repo) { + return Clone.clone(url, clonePath, opts).then(function(repo) { assert.ok(repo instanceof Repository); - repo.stateCleanup(); - repo.free(); }); }); it("can clone with filesystem", function() { + var test = this; var prefix = process.platform === "win32" ? "" : "file://"; var url = prefix + local("../repos/empty"); - return Clone.clone(url, file).then(function(repo) { + return Clone.clone(url, clonePath).then(function(repo) { assert.ok(repo instanceof Repository); - repo.stateCleanup(); - repo.free(); + test.repository = repo; }); }); it("will not segfault when accessing a url without username", function() { var url = "https://github.com/nodegit/private"; - return Clone.clone(url, git, { + return Clone.clone(url, clonePath, { remoteCallbacks: { certificateCheck: function() { return 1; From 0e80c58d7d72a05d002d8215b0286b6d864f5536 Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Tue, 24 Feb 2015 17:55:03 -0800 Subject: [PATCH 03/12] Ensure gc exists --- 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 0fdd344f0..693e051bb 100644 --- a/test/tests/clone.js +++ b/test/tests/clone.js @@ -28,7 +28,7 @@ describe("Clone", function() { } process.nextTick(function() { - gc(); + global.gc(); done(); }); }); From be57dcb67ad4a0fc24b4b5041469f1796324868e Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Tue, 24 Feb 2015 20:13:33 -0800 Subject: [PATCH 04/12] Trying to fix issue --- generate/scripts/generateNativeCode.js | 2 +- generate/templates/partials/sync_function.cc | 13 +++++++++++++ generate/templates/templates/class_content.cc | 1 + test/tests/clone.js | 6 +++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/generate/scripts/generateNativeCode.js b/generate/scripts/generateNativeCode.js index d93a08465..ec1249523 100644 --- a/generate/scripts/generateNativeCode.js +++ b/generate/scripts/generateNativeCode.js @@ -144,7 +144,7 @@ module.exports = function generateNativeCode() { }); } }) - }); + }).catch(console.log); }; diff --git a/generate/templates/partials/sync_function.cc b/generate/templates/partials/sync_function.cc index 8a8aab89e..56c53b99e 100644 --- a/generate/templates/partials/sync_function.cc +++ b/generate/templates/partials/sync_function.cc @@ -30,6 +30,12 @@ NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) { {%each args|argsInfo as arg %} {%endeach%} + +{%-- Inside a free call, if the value is already free'd don't do it again.--%} +{% if cppFunctionName == "Free" %} +if (ObjectWrap::Unwrap<{{ cppClassName }}>(args.This())->GetValue() != NULL) { +{% endif %} + {%if .|hasReturns %} {{ return.cType }} result = {%endif%}{{ cFunctionName }}( {%each args|argsInfo as arg %} @@ -67,6 +73,13 @@ from_{{ arg.name }} } {%endif%} +{% if cppFunctionName == "Free" %} +// FIXME Stuck here unable to NULL out this->repo +// ObjectWrap::Unwrap<{{ cppClassName }}>(args.This())->SetValue(NULL); +} +{% endif %} + + {%each args|argsInfo as arg %} {%if arg | isOid %} if (args[{{ arg.jsArg }}]->IsString()) { diff --git a/generate/templates/templates/class_content.cc b/generate/templates/templates/class_content.cc index fa5998a26..b5f5df327 100644 --- a/generate/templates/templates/class_content.cc +++ b/generate/templates/templates/class_content.cc @@ -35,6 +35,7 @@ using namespace node; {% if freeFunctionName %} if (this->selfFreeing) { {{ freeFunctionName }}(this->raw); + this->raw = NULL; } {% endif %} diff --git a/test/tests/clone.js b/test/tests/clone.js index 693e051bb..4b2e6ca14 100644 --- a/test/tests/clone.js +++ b/test/tests/clone.js @@ -18,7 +18,11 @@ describe("Clone", function() { this.timeout(30000); beforeEach(function() { - return fse.remove(clonePath); + return fse.remove(clonePath).catch(function(err) { + console.log(err); + + throw err; + }); }); afterEach(function(done) { From 7eb2108c06f7d4bfefccbbacd7dfd82b168a36ea Mon Sep 17 00:00:00 2001 From: John Haley Date: Tue, 24 Feb 2015 21:40:10 -0700 Subject: [PATCH 05/12] Add ClearValue method to structs and classes --- generate/templates/partials/sync_function.cc | 3 +-- generate/templates/templates/class_content.cc | 6 +++++- generate/templates/templates/class_header.h | 1 + generate/templates/templates/struct_content.cc | 6 +++++- generate/templates/templates/struct_header.h | 1 + 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/generate/templates/partials/sync_function.cc b/generate/templates/partials/sync_function.cc index 56c53b99e..136f8427c 100644 --- a/generate/templates/partials/sync_function.cc +++ b/generate/templates/partials/sync_function.cc @@ -74,8 +74,7 @@ from_{{ arg.name }} {%endif%} {% if cppFunctionName == "Free" %} -// FIXME Stuck here unable to NULL out this->repo -// ObjectWrap::Unwrap<{{ cppClassName }}>(args.This())->SetValue(NULL); + ObjectWrap::Unwrap<{{ cppClassName }}>(args.This())->ClearValue(); } {% endif %} diff --git a/generate/templates/templates/class_content.cc b/generate/templates/templates/class_content.cc index b5f5df327..c95c67214 100644 --- a/generate/templates/templates/class_content.cc +++ b/generate/templates/templates/class_content.cc @@ -113,7 +113,11 @@ using namespace node; } {{ cType }} **{{ cppClassName }}::GetRefValue() { - return &this->raw; + return this->raw == NULL ? NULL : &this->raw; + } + + void {{ cppClassName }}::ClearValue() { + this->raw = NULL; } {% else %} diff --git a/generate/templates/templates/class_header.h b/generate/templates/templates/class_header.h index b633ce200..322230770 100644 --- a/generate/templates/templates/class_header.h +++ b/generate/templates/templates/class_header.h @@ -38,6 +38,7 @@ class {{ cppClassName }} : public ObjectWrap { {%if cType%} {{ cType }} *GetValue(); {{ cType }} **GetRefValue(); + void ClearValue(); static Handle New(void *raw, bool selfFreeing); {%endif%} diff --git a/generate/templates/templates/struct_content.cc b/generate/templates/templates/struct_content.cc index 64b4dd628..d50be7654 100644 --- a/generate/templates/templates/struct_content.cc +++ b/generate/templates/templates/struct_content.cc @@ -138,7 +138,11 @@ Handle {{ cppClassName }}::New(void* raw, bool selfFreeing) { } {{ cType }} **{{ cppClassName }}::GetRefValue() { - return &this->raw; + return this->raw == NULL ? NULL : &this->raw; +} + +void {{ cppClassName }}::ClearValue() { + this->raw = NULL; } {% partial fieldAccessors . %} diff --git a/generate/templates/templates/struct_header.h b/generate/templates/templates/struct_header.h index d839d627e..c1e266bb3 100644 --- a/generate/templates/templates/struct_header.h +++ b/generate/templates/templates/struct_header.h @@ -26,6 +26,7 @@ class {{ cppClassName }} : public ObjectWrap { {{ cType }} *GetValue(); {{ cType }} **GetRefValue(); + void ClearValue(); static Handle New(void *raw, bool selfFreeing); From 98119a6bb161c7e14ba59a660008332c43478efa Mon Sep 17 00:00:00 2001 From: John Haley Date: Tue, 24 Feb 2015 22:31:23 -0700 Subject: [PATCH 06/12] Cleanup repo after each clone test --- test/tests/clone.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/tests/clone.js b/test/tests/clone.js index 4b2e6ca14..c95393d02 100644 --- a/test/tests/clone.js +++ b/test/tests/clone.js @@ -27,6 +27,7 @@ describe("Clone", function() { afterEach(function(done) { if (this.repository) { + this.repository.stateCleanup(); this.repository.free(); delete this.repository; } From 9141d595f872887b64092d0e56a90c13a615f3bb Mon Sep 17 00:00:00 2001 From: John Haley Date: Wed, 25 Feb 2015 08:39:37 -0700 Subject: [PATCH 07/12] Add unique directories to each clone test --- test/tests/clone.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/test/tests/clone.js b/test/tests/clone.js index c95393d02..0f4d10895 100644 --- a/test/tests/clone.js +++ b/test/tests/clone.js @@ -18,7 +18,7 @@ describe("Clone", function() { this.timeout(30000); beforeEach(function() { - return fse.remove(clonePath).catch(function(err) { + return fse.remove(this.clonePath).catch(function(err) { console.log(err); throw err; @@ -49,7 +49,9 @@ describe("Clone", function() { } }; - return Clone.clone(url, clonePath, opts).then(function(repo) { + test.clonePath = local("../repos/http"); + + return Clone.clone(url, test.clonePath, opts).then(function(repo) { assert.ok(repo instanceof Repository); test.repository = repo; }); @@ -66,7 +68,9 @@ describe("Clone", function() { } }; - return Clone.clone(url, clonePath, opts).then(function(repo) { + test.clonePath = local("../repos/https"); + + return Clone.clone(url, test.clonePath, opts).then(function(repo) { assert.ok(repo instanceof Repository); test.repository = repo; }); @@ -86,7 +90,9 @@ describe("Clone", function() { } }; - return Clone.clone(url, clonePath, opts).then(function(repo) { + test.clonePath = local("../repos/ssh"); + + return Clone.clone(url, test.clonePath, opts).then(function(repo) { assert.ok(repo instanceof Repository); test.repository = repo; }); @@ -110,7 +116,9 @@ describe("Clone", function() { } }; - return Clone.clone(url, clonePath, opts).then(function(repo) { + test.clonePath = local("../repos/sshManual"); + + return Clone.clone(url, test.clonePath, opts).then(function(repo) { assert.ok(repo instanceof Repository); test.repository = repo; }); @@ -126,7 +134,9 @@ describe("Clone", function() { } }; - return Clone.clone(url, clonePath, opts).then(function(repo) { + test.clonePath = local("../repos/git"); + + return Clone.clone(url, test.clonePath, opts).then(function(repo) { assert.ok(repo instanceof Repository); }); }); @@ -136,7 +146,9 @@ describe("Clone", function() { var prefix = process.platform === "win32" ? "" : "file://"; var url = prefix + local("../repos/empty"); - return Clone.clone(url, clonePath).then(function(repo) { + test.clonePath = local("../repos/filesystem"); + + return Clone.clone(url, test.clonePath).then(function(repo) { assert.ok(repo instanceof Repository); test.repository = repo; }); From 762fdf3a0519f8c3b24a739424309efb04572f91 Mon Sep 17 00:00:00 2001 From: John Haley Date: Wed, 25 Feb 2015 08:53:17 -0700 Subject: [PATCH 08/12] Fix null ref error in beforeEach --- test/tests/clone.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/tests/clone.js b/test/tests/clone.js index 0f4d10895..d198a2f00 100644 --- a/test/tests/clone.js +++ b/test/tests/clone.js @@ -18,11 +18,13 @@ describe("Clone", function() { this.timeout(30000); beforeEach(function() { - return fse.remove(this.clonePath).catch(function(err) { - console.log(err); + if (this.clonePath) { + return fse.remove(this.clonePath).catch(function(err) { + console.log(err); - throw err; - }); + throw err; + }); + } }); afterEach(function(done) { From 90d580a0c1362bf6351ded26aec5a68f91d46227 Mon Sep 17 00:00:00 2001 From: John Haley Date: Wed, 25 Feb 2015 09:34:33 -0700 Subject: [PATCH 09/12] Fix test var null ref --- test/tests/clone.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/tests/clone.js b/test/tests/clone.js index d198a2f00..5ecd3dd28 100644 --- a/test/tests/clone.js +++ b/test/tests/clone.js @@ -127,6 +127,7 @@ describe("Clone", function() { }); it("can clone with git", function() { + var test = this; var url = "git://github.com/nodegit/test.git"; var opts = { remoteCallbacks: { From 796c09f66c77128986b9306ebeac6806258c6e45 Mon Sep 17 00:00:00 2001 From: John Haley Date: Wed, 25 Feb 2015 14:27:44 -0700 Subject: [PATCH 10/12] Add repo from git clone to test instance so it can be cleaned up --- test/tests/clone.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/tests/clone.js b/test/tests/clone.js index 5ecd3dd28..0b0633072 100644 --- a/test/tests/clone.js +++ b/test/tests/clone.js @@ -140,6 +140,7 @@ describe("Clone", function() { test.clonePath = local("../repos/git"); return Clone.clone(url, test.clonePath, opts).then(function(repo) { + test.repository = repo; assert.ok(repo instanceof Repository); }); }); From e19e8eaad8969d1825a4694e6fc05ff260d367f9 Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 25 Feb 2015 17:21:30 -0500 Subject: [PATCH 11/12] Added global `afterEach`, standardized repo attach I ensured that every time we work with a repository it is attached under `test.repository`. This makes our `afterEach` much more consistent and concise. I changed the `free` code to only occur under Windows, where file locking is still a thing. --- test/runner.js | 15 ++++++++++++++ test/tests/branch.js | 8 ++++---- test/tests/checkout.js | 12 +++++------ test/tests/clone.js | 45 +++++++++--------------------------------- test/tests/index.js | 8 ++++---- 5 files changed, 38 insertions(+), 50 deletions(-) diff --git a/test/runner.js b/test/runner.js index 3f78715f4..10de2045a 100644 --- a/test/runner.js +++ b/test/runner.js @@ -45,3 +45,18 @@ beforeEach(function() { return exec("git reset --hard", {cwd: workdirPath}); }); }); + +afterEach(function(done) { + // In Windows if you do not clean up the repository, there may become a + // conflict with file locking. + if (this.repository && process.platform === "win32") { + this.repository.stateCleanup(); + this.repository.free(); + delete this.repository; + } + + process.nextTick(function() { + global.gc(); + done(); + }); +}); diff --git a/test/tests/branch.js b/test/tests/branch.js index 71f3d8986..5c7b67de2 100644 --- a/test/tests/branch.js +++ b/test/tests/branch.js @@ -16,13 +16,13 @@ describe("Branch", function() { return Repository.open(reposPath) .then(function(repository) { - test.repo = repository; + test.repository = repository; }); }); beforeEach(function() { var test = this; - var repo = test.repo; + var repo = test.repository; return repo.getMasterCommit() .then(function(masterCommit) { @@ -44,7 +44,7 @@ describe("Branch", function() { }); it("can delete a branch", function() { - var repo = this.repo; + var repo = this.repository; Branch.delete(this.branch); @@ -54,7 +54,7 @@ describe("Branch", function() { }); it("can see if the branch is pointed to by head", function() { - var repo = this.repo; + var repo = this.repository; return repo.getBranch("master") .then(function(branch) { diff --git a/test/tests/checkout.js b/test/tests/checkout.js index 73acb1daa..030e17cf0 100644 --- a/test/tests/checkout.js +++ b/test/tests/checkout.js @@ -14,16 +14,16 @@ describe("Checkout", function() { return Repository.open(reposPath) .then(function(repo) { - test.repo = repo; + test.repository = repo; }); }); it("can checkout the head", function() { var test = this; - return Checkout.head(test.repo) + return Checkout.head(test.repository) .then(function() { - return test.repo.getBlob(packageJsonOid); + return test.repository.getBlob(packageJsonOid); }) .then(function(blob) { var packageJson = blob.toString(); @@ -35,10 +35,10 @@ describe("Checkout", function() { it("can checkout by tree", function() { var test = this; - return test.repo.getTagByName("annotated-tag").then(function(tag) { - return Checkout.tree(test.repo, test.tag); + return test.repository.getTagByName("annotated-tag").then(function(tag) { + return Checkout.tree(test.repository, test.tag); }).then(function() { - return test.repo.getHeadCommit(); + return test.repository.getHeadCommit(); }).then(function(commit) { assert.equal(commit, "32789a79e71fbc9e04d3eff7425e1771eb595150"); }); diff --git a/test/tests/clone.js b/test/tests/clone.js index 0b0633072..100ba77a4 100644 --- a/test/tests/clone.js +++ b/test/tests/clone.js @@ -18,25 +18,10 @@ describe("Clone", function() { this.timeout(30000); beforeEach(function() { - if (this.clonePath) { - return fse.remove(this.clonePath).catch(function(err) { - console.log(err); + return fse.remove(clonePath).catch(function(err) { + console.log(err); - throw err; - }); - } - }); - - afterEach(function(done) { - if (this.repository) { - this.repository.stateCleanup(); - this.repository.free(); - delete this.repository; - } - - process.nextTick(function() { - global.gc(); - done(); + throw err; }); }); @@ -51,9 +36,7 @@ describe("Clone", function() { } }; - test.clonePath = local("../repos/http"); - - return Clone.clone(url, test.clonePath, opts).then(function(repo) { + return Clone.clone(url, clonePath, opts).then(function(repo) { assert.ok(repo instanceof Repository); test.repository = repo; }); @@ -70,9 +53,7 @@ describe("Clone", function() { } }; - test.clonePath = local("../repos/https"); - - return Clone.clone(url, test.clonePath, opts).then(function(repo) { + return Clone.clone(url, clonePath, opts).then(function(repo) { assert.ok(repo instanceof Repository); test.repository = repo; }); @@ -92,9 +73,7 @@ describe("Clone", function() { } }; - test.clonePath = local("../repos/ssh"); - - return Clone.clone(url, test.clonePath, opts).then(function(repo) { + return Clone.clone(url, clonePath, opts).then(function(repo) { assert.ok(repo instanceof Repository); test.repository = repo; }); @@ -118,9 +97,7 @@ describe("Clone", function() { } }; - test.clonePath = local("../repos/sshManual"); - - return Clone.clone(url, test.clonePath, opts).then(function(repo) { + return Clone.clone(url, clonePath, opts).then(function(repo) { assert.ok(repo instanceof Repository); test.repository = repo; }); @@ -137,9 +114,7 @@ describe("Clone", function() { } }; - test.clonePath = local("../repos/git"); - - return Clone.clone(url, test.clonePath, opts).then(function(repo) { + return Clone.clone(url, clonePath, opts).then(function(repo) { test.repository = repo; assert.ok(repo instanceof Repository); }); @@ -150,9 +125,7 @@ describe("Clone", function() { var prefix = process.platform === "win32" ? "" : "file://"; var url = prefix + local("../repos/empty"); - test.clonePath = local("../repos/filesystem"); - - return Clone.clone(url, test.clonePath).then(function(repo) { + return Clone.clone(url, clonePath).then(function(repo) { assert.ok(repo instanceof Repository); test.repository = repo; }); diff --git a/test/tests/index.js b/test/tests/index.js index 7b29e2d89..55fdc908b 100644 --- a/test/tests/index.js +++ b/test/tests/index.js @@ -19,7 +19,7 @@ describe("Index", function() { return Repository.open(reposPath) .then(function(repo) { - test.repo = repo; + test.repository = repo; return repo.openIndex(); }) .then(function(index) { @@ -38,7 +38,7 @@ describe("Index", function() { }); it("can add all entries to the index", function() { - var repo = this.repo; + var repo = this.repository; var index = this.index; var fileContent = { newFile1: "this has some content", @@ -72,7 +72,7 @@ describe("Index", function() { }); it("can remove entries from the index", function() { - var repo = this.repo; + var repo = this.repository; var index = this.index; var fileContent = { newFile1: "this has some content", @@ -116,7 +116,7 @@ describe("Index", function() { }); it("can update entries in the index", function() { - var repo = this.repo; + var repo = this.repository; var index = this.index; var fileContent = { newFile1: "this has some content", From 342b6e68d046030c0e1a6f352b795743158eb0dd Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Wed, 25 Feb 2015 15:21:55 -0800 Subject: [PATCH 12/12] Converted to `beforeEach` for all tests Added a new `beforeEach` to ensure repositories are cleaned in clone, not sure why this is required. --- test/tests/attr.js | 2 +- test/tests/blob.js | 2 +- test/tests/branch.js | 14 ++++---------- test/tests/checkout.js | 2 +- test/tests/clone.js | 15 +++++++++++++++ test/tests/commit.js | 2 +- test/tests/diff.js | 2 +- test/tests/index.js | 2 +- test/tests/odb.js | 2 +- test/tests/remote.js | 2 +- test/tests/repository.js | 2 +- test/tests/reset.js | 2 +- test/tests/revwalk.js | 4 ++-- test/tests/tag.js | 14 +++++++------- 14 files changed, 38 insertions(+), 29 deletions(-) diff --git a/test/tests/attr.js b/test/tests/attr.js index e9dc9a326..8ea0fbe2e 100644 --- a/test/tests/attr.js +++ b/test/tests/attr.js @@ -9,7 +9,7 @@ describe("Attr", function() { var reposPath = local("../repos/workdir/.git"); - before(function() { + beforeEach(function() { var test = this; return Repository.open(reposPath) diff --git a/test/tests/blob.js b/test/tests/blob.js index 608d3a351..3b245ac27 100644 --- a/test/tests/blob.js +++ b/test/tests/blob.js @@ -10,7 +10,7 @@ describe("Blob", function() { var reposPath = local("../repos/workdir/.git"); var oid = "111dd657329797f6165f52f5085f61ac976dcf04"; - before(function() { + beforeEach(function() { var test = this; return Repository.open(reposPath) diff --git a/test/tests/branch.js b/test/tests/branch.js index 5c7b67de2..dfa7b1d2f 100644 --- a/test/tests/branch.js +++ b/test/tests/branch.js @@ -11,24 +11,18 @@ describe("Branch", function() { var reposPath = local("../repos/workdir/.git"); - before(function() { + beforeEach(function() { var test = this; return Repository.open(reposPath) .then(function(repository) { test.repository = repository; - }); - }); - - beforeEach(function() { - var test = this; - var repo = test.repository; - - return repo.getMasterCommit() + return repository.getMasterCommit(); + }) .then(function(masterCommit) { test.masterCommit = masterCommit; - return repo.createBranch(branchName, masterCommit, true); + return test.repository.createBranch(branchName, masterCommit, true); }) .then(function(branch) { test.branch = branch; diff --git a/test/tests/checkout.js b/test/tests/checkout.js index 030e17cf0..c00c84a3c 100644 --- a/test/tests/checkout.js +++ b/test/tests/checkout.js @@ -9,7 +9,7 @@ describe("Checkout", function() { var packageJsonOid = "0fa56e90e096a4c24c785206b826ab914ea3de1e"; var reposPath = local("../repos/workdir/.git"); - before(function() { + beforeEach(function() { var test = this; return Repository.open(reposPath) diff --git a/test/tests/clone.js b/test/tests/clone.js index 100ba77a4..51c636b21 100644 --- a/test/tests/clone.js +++ b/test/tests/clone.js @@ -17,6 +17,21 @@ describe("Clone", function() { // Set a reasonable timeout here now that our repository has grown. this.timeout(30000); + beforeEach(function(done) { + // In Windows if you do not clean up the repository, there may become a + // conflict with file locking. + if (this.repository && process.platform === "win32") { + this.repository.stateCleanup(); + this.repository.free(); + delete this.repository; + } + + process.nextTick(function() { + global.gc(); + done(); + }); + }); + beforeEach(function() { return fse.remove(clonePath).catch(function(err) { console.log(err); diff --git a/test/tests/commit.js b/test/tests/commit.js index 9ef203495..b15ac7d52 100644 --- a/test/tests/commit.js +++ b/test/tests/commit.js @@ -24,7 +24,7 @@ describe("Commit", function() { }); } - before(function() { + beforeEach(function() { return reinitialize(this); }); diff --git a/test/tests/diff.js b/test/tests/diff.js index 391f6c8f9..af5c8a259 100644 --- a/test/tests/diff.js +++ b/test/tests/diff.js @@ -14,7 +14,7 @@ describe("Diff", function() { var diffFilename = "wddiff.txt"; var diffFilepath = local("../repos/workdir", diffFilename); - before(function() { + beforeEach(function() { var test = this; return Repository.open(reposPath).then(function(repository) { diff --git a/test/tests/index.js b/test/tests/index.js index 55fdc908b..4ce034de4 100644 --- a/test/tests/index.js +++ b/test/tests/index.js @@ -14,7 +14,7 @@ describe("Index", function() { var reposPath = local("../repos/workdir/.git"); - before(function() { + beforeEach(function() { var test = this; return Repository.open(reposPath) diff --git a/test/tests/odb.js b/test/tests/odb.js index 5a7d5fba9..b594d14bc 100644 --- a/test/tests/odb.js +++ b/test/tests/odb.js @@ -9,7 +9,7 @@ describe("Odb", function() { var reposPath = local("../repos/workdir/.git"); - before(function() { + beforeEach(function() { var test = this; return Repository.open(reposPath).then(function(repo) { diff --git a/test/tests/remote.js b/test/tests/remote.js index a74245ddf..104052a14 100644 --- a/test/tests/remote.js +++ b/test/tests/remote.js @@ -19,7 +19,7 @@ describe("Remote", function() { Remote.delete(repository, "test2"); } - before(function() { + beforeEach(function() { var test = this; return Repository.open(reposPath) diff --git a/test/tests/repository.js b/test/tests/repository.js index ed3583fd6..13d59c947 100644 --- a/test/tests/repository.js +++ b/test/tests/repository.js @@ -13,7 +13,7 @@ describe("Repository", function() { var Index = require(local("../../lib/index")); var Signature = require(local("../../lib/signature")); - before(function() { + beforeEach(function() { var test = this; return Repository.open(reposPath) diff --git a/test/tests/reset.js b/test/tests/reset.js index 9c3b0e23f..5c42eceb2 100644 --- a/test/tests/reset.js +++ b/test/tests/reset.js @@ -13,7 +13,7 @@ describe("Reset", function() { var previousCommitOid = "c82fb078a192ea221c9f1093c64321c60d64aa0d"; var filePath = "package.json"; - before(function() { + beforeEach(function() { var test = this; return Repository.open(reposPath) diff --git a/test/tests/revwalk.js b/test/tests/revwalk.js index 833014c38..9a2cc4dfc 100644 --- a/test/tests/revwalk.js +++ b/test/tests/revwalk.js @@ -12,7 +12,7 @@ describe("Revwalk", function() { // Set a reasonable timeout here now that our repository has grown. this.timeout(60000); - before(function() { + beforeEach(function() { var test = this; return Repository.open(reposPath) .then(function(repository) { @@ -152,7 +152,7 @@ describe("Revwalk", function() { } } return promise; - + function getNext() { return walker.next(); } diff --git a/test/tests/tag.js b/test/tests/tag.js index 06dc9a880..1f2ffca00 100644 --- a/test/tests/tag.js +++ b/test/tests/tag.js @@ -26,31 +26,31 @@ describe("Tag", function() { assert.equal(target.id().toString(), commitPointedTo); } - before(function() { + beforeEach(function() { var test = this; return Repository.open(reposPath) .then(function(repo) { - test.repo = repo; + test.repository = repo; }); }); it("can get a tag from a repo via the tag name", function() { - return this.repo.getTagByName(tagName) + return this.repository.getTagByName(tagName) .then(function(tag) { testTag(tag); }); }); it("can get a tag from a repo via the long tag name", function() { - return this.repo.getTagByName(tagFullName) + return this.repository.getTagByName(tagFullName) .then(function(tag) { testTag(tag); }); }); it("can get a tag from a repo via the tag's OID as a string", function() { - return this.repo.getTag(tagOid) + return this.repository.getTag(tagOid) .then(function(tag) { testTag(tag); }); @@ -59,14 +59,14 @@ describe("Tag", function() { it("can get a tag from a repo via the tag's OID object", function() { var oid = Oid.fromString(tagOid); - return this.repo.getTag(oid) + return this.repository.getTag(oid) .then(function(tag) { testTag(tag); }); }); it("can list tags in a repo", function() { - return Tag.list(this.repo) + return Tag.list(this.repository) .then(function(tagNames) { tagNames = tagNames.filter(function(tagNameTest) { return tagNameTest == tagName;