Skip to content

Commit 29a9a82

Browse files
committed
Automatically free repositories post clone
Once a repository has been successfully cloned, free the internal structure to avoid file locking. Then open the repository again to providea repository opbject.
1 parent 89a10df commit 29a9a82

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

lib/clone.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,21 @@ Clone.clone = function(url, local_path, options) {
2828
normalizeOptions(remoteCallbacks, NodeGit.RemoteCallbacks);
2929
}
3030

31-
return clone.call(this, url, local_path, options);
31+
// This is required to clean up after the clone to avoid file locking
32+
// issues in Windows and potentially other issues we don't know about.
33+
var freeRepository = function(repository) {
34+
repository.free();
35+
};
36+
37+
// We want to provide a valid repository object, so reopen the repository
38+
// after clone and cleanup.
39+
var openRepository = function() {
40+
return NodeGit.Repository.open(local_path);
41+
};
42+
43+
return clone.call(this, url, local_path, options)
44+
.then(freeRepository)
45+
.then(openRepository);
3246
};
3347

3448
module.exports = Clone;

test/runner.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,6 @@ beforeEach(function() {
4747
});
4848

4949
afterEach(function(done) {
50-
// In Windows if you do not clean up the repository, there may become a
51-
// conflict with file locking.
52-
if (this.repository && process.platform === "win32") {
53-
this.repository.stateCleanup();
54-
this.repository.free();
55-
delete this.repository;
56-
}
57-
5850
process.nextTick(function() {
5951
global.gc();
6052
done();

test/tests/clone.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,6 @@ describe("Clone", function() {
1717
// Set a reasonable timeout here now that our repository has grown.
1818
this.timeout(30000);
1919

20-
beforeEach(function(done) {
21-
// In Windows if you do not clean up the repository, there may become a
22-
// conflict with file locking.
23-
if (this.repository && process.platform === "win32") {
24-
this.repository.stateCleanup();
25-
this.repository.free();
26-
delete this.repository;
27-
}
28-
29-
process.nextTick(function() {
30-
global.gc();
31-
done();
32-
});
33-
});
34-
3520
beforeEach(function() {
3621
return fse.remove(clonePath).catch(function(err) {
3722
console.log(err);

0 commit comments

Comments
 (0)