diff --git a/lib/clone.js b/lib/clone.js index 7b6fefcfb..e6f51bf3c 100644 --- a/lib/clone.js +++ b/lib/clone.js @@ -28,7 +28,21 @@ Clone.clone = function(url, local_path, options) { normalizeOptions(remoteCallbacks, NodeGit.RemoteCallbacks); } - return clone.call(this, url, local_path, options); + // This is required to clean up after the clone to avoid file locking + // issues in Windows and potentially other issues we don't know about. + var freeRepository = function(repository) { + repository.free(); + }; + + // We want to provide a valid repository object, so reopen the repository + // after clone and cleanup. + var openRepository = function() { + return NodeGit.Repository.open(local_path); + }; + + return clone.call(this, url, local_path, options) + .then(freeRepository) + .then(openRepository); }; module.exports = Clone; diff --git a/test/runner.js b/test/runner.js index 10de2045a..a44b3b027 100644 --- a/test/runner.js +++ b/test/runner.js @@ -47,14 +47,6 @@ beforeEach(function() { }); 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/clone.js b/test/tests/clone.js index 51c636b21..100ba77a4 100644 --- a/test/tests/clone.js +++ b/test/tests/clone.js @@ -17,21 +17,6 @@ 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);