Skip to content

Commit 50bb365

Browse files
committed
Merge pull request nodegit#1017 from nodegit/libgit2-submodule
Make libgit2 an actual submodule
2 parents ebc73a8 + b936634 commit 50bb365

File tree

4,988 files changed

+185
-246133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,988 files changed

+185
-246133
lines changed

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "vendor/libgit2"]
2+
path = vendor/libgit2
3+
[submodule "vendor/libgit2"]
4+
url = https://github.com/nodegit/libgit2.git

generate/index.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
11
var generateJson = require("./scripts/generateJson");
22
var generateNativeCode = require("./scripts/generateNativeCode");
33
var generateMissingTests = require("./scripts/generateMissingTests");
4+
var submoduleStatus = require("../lifecycleScripts/submodules/getStatus");
45

56
module.exports = function generate() {
6-
return new Promise(function(resolve, reject) {
7-
try {
7+
return submoduleStatus()
8+
.then(function(statuses) {
9+
var dirtySubmodules = statuses
10+
.filter(function(status) {
11+
return status.onNewCommit
12+
|| status.needsInitialization
13+
|| status.workDirDirty;
14+
});
15+
16+
if (dirtySubmodules.length) {
17+
console.log("WARNING - Some submodules are out-of-sync");
18+
dirtySubmodules.forEach(function(submodule) {
19+
console.log("\t" + submodule.name);
20+
});
21+
}
22+
})
23+
.then(function() {
824
generateJson();
925
generateNativeCode();
1026
generateMissingTests();
11-
resolve();
12-
}
13-
catch(e) {
14-
reject(e);
15-
}
16-
});
27+
})
28+
.catch(function(e) {
29+
console.log("ERROR - Could not generate native code");
30+
console.log(e);
31+
});
1732
}
1833

1934
if (require.main === module) {

generate/scripts/generateNativeCode.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
const path = require("path");
22
const promisify = require("promisify-node");
33
const fse = promisify(require("fs-extra"));
4-
const exec = promisify(function(command, opts, callback) {
5-
return require("child_process").exec(command, opts, callback);
6-
});
7-
4+
const exec = require('../../utils/execPromise');
85
const utils = require("./utils");
96

107
module.exports = function generateNativeCode() {

lifecycleScripts/install.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
var promisify = require("promisify-node");
21
var path = require("path");
32
var fs = require("fs");
43
var cp = require("child_process");
54
var prepareForBuild = require("./prepareForBuild");
6-
7-
var exec = promisify(function(command, opts, callback) {
8-
return cp.exec(command, opts, callback);
9-
});
5+
var exec = require("../utils/execPromise");
106

117
var fromRegistry;
8+
129
try {
1310
fs.statSync(path.join(__dirname, "..", "include"));
1411
fs.statSync(path.join(__dirname, "..", "src"));
@@ -124,7 +121,6 @@ function build() {
124121
return arg;
125122
});
126123

127-
console.log(args);
128124
return new Promise(function(resolve, reject) {
129125
var child = cp.spawn(cmd, args, opts);
130126
child.on("close", function(code) {

lifecycleScripts/prepareForBuild.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ var path = require("path");
33

44
var local = path.join.bind(path, __dirname);
55

6+
var submodules = require(local("submodules"));
67
var configure = require(local("configureLibssh2"));
78
var generate = require(local("../generate"));
89

910
module.exports = function prepareForBuild() {
10-
1111
return new Promise(function(resolve, reject) {
1212
cp.exec("npm install --ignore-scripts", function(err, stdout, stderr) {
1313
if (err) {
@@ -19,7 +19,11 @@ module.exports = function prepareForBuild() {
1919
console.info(stdout);
2020
}
2121
});
22-
}).then(function() {
22+
})
23+
.then(function() {
24+
return submodules();
25+
})
26+
.then(function() {
2327
return Promise.all([
2428
configure(),
2529
generate()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var path = require("path");
2+
var rootDir = path.join(__dirname, "../..");
3+
var exec = require(path.join(rootDir, "./utils/execPromise"));
4+
5+
module.exports = function getStatus() {
6+
return exec("git submodule status", { cwd: rootDir})
7+
.then(function(stdout) {
8+
function getStatusPromiseFromLine(line) {
9+
var lineSections = line.trim().split(" ");
10+
var onNewCommit = !!~lineSections[0].indexOf("+");
11+
var needsInitialization = !!~lineSections[0].indexOf("-");
12+
var commitOid = lineSections[0].replace("+", "").replace("-", "");
13+
var name = lineSections[1];
14+
15+
return exec("git status", { cwd: path.join(rootDir, name)})
16+
.then(function(workDirStatus) {
17+
return {
18+
commitOid: commitOid,
19+
onNewCommit: onNewCommit,
20+
name: name,
21+
needsInitialization: needsInitialization,
22+
workDirDirty: !~workDirStatus
23+
.trim()
24+
.split("\n")
25+
.pop()
26+
.indexOf("nothing to commit")
27+
};
28+
});
29+
}
30+
31+
return Promise.all(stdout
32+
.trim()
33+
.split("\n")
34+
.map(getStatusPromiseFromLine)
35+
);
36+
});
37+
};

lifecycleScripts/submodules/index.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
var path = require("path");
2+
var rootDir = path.join(__dirname, "../..");
3+
4+
var gitExecutableLocation = require(
5+
path.join(rootDir, "./utils/gitExecutableLocation")
6+
);
7+
var submoduleStatus = require("./getStatus");
8+
9+
var exec = require(path.join(rootDir, "./utils/execPromise"));
10+
11+
module.exports = function submodules() {
12+
return gitExecutableLocation()
13+
.catch(function() {
14+
console.log("ERROR - Compilation of NodeGit requires git CLI to be " +
15+
"installed and on the path");
16+
17+
throw new Error("git CLI is not installed or not on the path");
18+
})
19+
.then(function() {
20+
return submoduleStatus();
21+
})
22+
.then(function(statuses) {
23+
function printSubmodule(submoduleName) {
24+
console.log("\t" + submoduleName);
25+
}
26+
27+
var dirtySubmodules = statuses
28+
.filter(function(status) {
29+
return status.workDirDirty && !status.needsInitialization;
30+
})
31+
.map(function(dirtySubmodule) {
32+
return dirtySubmodule.name;
33+
});
34+
35+
if (dirtySubmodules.length) {
36+
console.log(
37+
"ERROR - The following submodules have uncommited changes:"
38+
);
39+
dirtySubmodules.forEach(printSubmodule);
40+
console.log(
41+
"\nThey must either be committed or discarded before we build"
42+
);
43+
44+
throw new Error("Dirty Submodules: " + dirtySubmodules.join(" "));
45+
}
46+
47+
var outOfSyncSubmodules = statuses
48+
.filter(function(status) {
49+
return status.onNewCommit && !status.needsInitialization;
50+
})
51+
.map(function(outOfSyncSubmodule) {
52+
return outOfSyncSubmodule.name;
53+
});
54+
55+
if (outOfSyncSubmodules.length) {
56+
console.log(
57+
"WARNING - The following submodules are pointing to an new commit:"
58+
);
59+
outOfSyncSubmodules.forEach(printSubmodule);
60+
console.log("\nThey will not be updated.");
61+
}
62+
63+
return Promise.all(statuses
64+
.filter(function(status) {
65+
return !status.onNewCommit;
66+
})
67+
.map(function(submoduleToUpdate) {
68+
return exec(
69+
"git submodule update --init --recursive " + submoduleToUpdate.name
70+
);
71+
})
72+
);
73+
});
74+
};

test/runner.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var promisify = require("promisify-node");
22
var fse = promisify("fs-extra");
33
var path = require("path");
44
var local = path.join.bind(path, __dirname);
5+
var exec = require('../utils/execPromise');
56

67
var NodeGit = require('..');
78

@@ -13,11 +14,6 @@ if(process.env.NODEGIT_TEST_THREADSAFETY) {
1314
NodeGit.setThreadSafetyStatus(NodeGit.THREAD_SAFETY.ENABLED_FOR_ASYNC_ONLY);
1415
}
1516

16-
// Have to wrap exec, since it has a weird callback signature.
17-
var exec = promisify(function(command, opts, callback) {
18-
return require("child_process").exec(command, opts, callback);
19-
});
20-
2117
var workdirPath = local("repos/workdir");
2218

2319
before(function() {

test/tests/commit.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ var leakTest = require("../utils/leak_test");
88

99
var local = path.join.bind(path, __dirname);
1010

11-
// Have to wrap exec, since it has a weird callback signature.
12-
var exec = promisify(function(command, opts, callback) {
13-
return require("child_process").exec(command, opts, callback);
14-
});
11+
var exec = require("../../utils/execPromise");
1512

1613
describe("Commit", function() {
1714
var NodeGit = require("../../");

test/tests/config.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
var assert = require("assert");
22
var path = require("path");
33
var local = path.join.bind(path, __dirname);
4-
var promisify = require("promisify-node");
54

6-
// Have to wrap exec, since it has a weird callback signature.
7-
var exec = promisify(function(command, opts, callback) {
8-
return require("child_process").exec(command, opts, callback);
9-
});
5+
var exec = require("../../utils/execPromise");
106

117
describe("Config", function() {
128
var NodeGit = require("../../");

test/tests/refs.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
var assert = require("assert");
22
var path = require("path");
3-
var promisify = require("promisify-node");
43
var local = path.join.bind(path, __dirname);
54

6-
// Have to wrap exec, since it has a weird callback signature.
7-
var exec = promisify(function(command, opts, callback) {
8-
return require("child_process").exec(command, opts, callback);
9-
});
5+
var exec = require("../../utils/execPromise");
106

117
describe("Reference", function() {
128
var NodeGit = require("../../");

test/tests/signature.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
var assert = require("assert");
22
var path = require("path");
33
var local = path.join.bind(path, __dirname);
4-
var promisify = require("promisify-node");
54

6-
// Have to wrap exec, since it has a weird callback signature.
7-
var exec = promisify(function(command, opts, callback) {
8-
return require("child_process").exec(command, opts, callback);
9-
});
5+
var exec = require("../../utils/execPromise");
106

117
describe("Signature", function() {
128
var NodeGit = require("../../");

test/tests/stage.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ var path = require("path");
33
var promisify = require("promisify-node");
44
var fse = promisify(require("fs-extra"));
55

6-
var exec = promisify(function(command, opts, callback) {
7-
return require("child_process").exec(command, opts, callback);
8-
});
6+
var exec = require("../../utils/execPromise");
97

108
describe("Stage", function() {
119
var RepoUtils = require("../utils/repository_setup");

test/tests/status.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ var path = require("path");
33
var promisify = require("promisify-node");
44
var fse = promisify(require("fs-extra"));
55
var local = path.join.bind(path, __dirname);
6-
var exec = promisify(function(command, opts, callback) {
7-
return require("child_process").exec(command, opts, callback);
8-
});
6+
var exec = require("../../utils/execPromise");
97

108
describe("Status", function() {
119
var NodeGit = require("../../");

test/tests/status_list.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ var path = require("path");
33
var promisify = require("promisify-node");
44
var fse = promisify(require("fs-extra"));
55
var local = path.join.bind(path, __dirname);
6-
var exec = promisify(function(command, opts, callback) {
7-
return require("child_process").exec(command, opts, callback);
8-
});
6+
var exec = require("../../utils/execPromise");
97

108
describe("StatusList", function() {
119
var NodeGit = require("../../");

utils/execPromise.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var promisify = require("promisify-node");
2+
var cp = require('child_process');
3+
4+
module.exports = promisify(function(command, opts, callback) {
5+
return cp.exec(command, opts, callback);
6+
});

utils/gitExecutableLocation.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var cp = require("child_process");
2+
3+
module.exports = function gitExecutableLocation() {
4+
return new Promise(function(resolve, reject) {
5+
var cmd;
6+
7+
if (process.platform === "win32") {
8+
cmd = "where git";
9+
}
10+
else {
11+
cmd = "which git";
12+
}
13+
14+
cp.exec(cmd, function(err, stdout, stderr) {
15+
if (err) {
16+
reject(err, stderr);
17+
}
18+
else {
19+
resolve(stdout);
20+
}
21+
});
22+
});
23+
};

vendor/libgit2

Submodule libgit2 added at 211e117

vendor/libgit2/.HEADER

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)