@swimlane/nodegit 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +2 -0
- package/.github/workflows/publish.yml +126 -0
- package/.github/workflows/tests.yml +85 -0
- package/LICENSE +19 -0
- package/README.md +193 -0
- package/lib/attr.js +20 -0
- package/lib/blob.js +51 -0
- package/lib/branch.js +19 -0
- package/lib/buf.js +43 -0
- package/lib/commit.js +437 -0
- package/lib/config.js +48 -0
- package/lib/convenient_hunks.js +61 -0
- package/lib/convenient_patch.js +131 -0
- package/lib/credential.js +33 -0
- package/lib/deprecated/structs/ApplyOptions.js +3 -0
- package/lib/deprecated/structs/BlameOptions.js +6 -0
- package/lib/deprecated/structs/BlobFilterOptions.js +3 -0
- package/lib/deprecated/structs/CheckoutOptions.js +8 -0
- package/lib/deprecated/structs/CherrypickOptions.js +5 -0
- package/lib/deprecated/structs/CloneOptions.js +6 -0
- package/lib/deprecated/structs/DescribeFormatOptions.js +4 -0
- package/lib/deprecated/structs/DescribeOptions.js +6 -0
- package/lib/deprecated/structs/DiffFindOptions.js +8 -0
- package/lib/deprecated/structs/DiffOptions.js +8 -0
- package/lib/deprecated/structs/FetchOptions.js +7 -0
- package/lib/deprecated/structs/MergeFileInput.js +4 -0
- package/lib/deprecated/structs/MergeFileOptions.js +5 -0
- package/lib/deprecated/structs/MergeOptions.js +8 -0
- package/lib/deprecated/structs/ProxyOptions.js +3 -0
- package/lib/deprecated/structs/PushOptions.js +5 -0
- package/lib/deprecated/structs/RebaseOptions.js +6 -0
- package/lib/deprecated/structs/RemoteCreateOptions.js +3 -0
- package/lib/deprecated/structs/RepositoryInitOptions.js +4 -0
- package/lib/deprecated/structs/RevertOptions.js +5 -0
- package/lib/deprecated/structs/StashApplyOptions.js +4 -0
- package/lib/deprecated/structs/StatusOptions.js +4 -0
- package/lib/deprecated/structs/SubmoduleUpdateOptions.js +5 -0
- package/lib/diff.js +67 -0
- package/lib/diff_file.js +38 -0
- package/lib/diff_line.js +32 -0
- package/lib/error.js +17 -0
- package/lib/filter_registry.js +22 -0
- package/lib/graph.js +15 -0
- package/lib/index.js +103 -0
- package/lib/merge.js +41 -0
- package/lib/note.js +17 -0
- package/lib/object.js +45 -0
- package/lib/odb_object.js +9 -0
- package/lib/oid.js +23 -0
- package/lib/rebase.js +86 -0
- package/lib/reference.js +213 -0
- package/lib/remote.js +45 -0
- package/lib/repository.js +1973 -0
- package/lib/reset.js +51 -0
- package/lib/revparse.js +18 -0
- package/lib/revwalk.js +142 -0
- package/lib/signature.js +38 -0
- package/lib/stash.js +16 -0
- package/lib/status.js +16 -0
- package/lib/status_file.js +106 -0
- package/lib/submodule.js +10 -0
- package/lib/tag.js +141 -0
- package/lib/tree.js +175 -0
- package/lib/tree_entry.js +99 -0
- package/lib/utils/lookup_wrapper.js +39 -0
- package/lib/utils/shallow_clone.js +14 -0
- package/lifecycleScripts/clean.js +5 -0
- package/lifecycleScripts/install.js +32 -0
- package/lifecycleScripts/postinstall.js +83 -0
- package/lifecycleScripts/preinstall.js +47 -0
- package/lifecycleScripts/submodules/getStatus.js +50 -0
- package/lifecycleScripts/submodules/index.js +84 -0
- package/package.json +83 -0
- package/prebuilds/darwin-arm64/@swimlane+nodegit.glibc.node +0 -0
- package/prebuilds/darwin-x64/@swimlane+nodegit.glibc.node +0 -0
- package/prebuilds/linux-arm64/@swimlane+nodegit.glibc.node +0 -0
- package/prebuilds/linux-x64/@swimlane+nodegit.glibc.node +0 -0
- package/prebuilds/linux-x64/@swimlane+nodegit.musl.node +0 -0
- package/scripts/Dockerfile.alpine +10 -0
- package/scripts/Dockerfile.debian +15 -0
- package/utils/acquireOpenSSL.js +436 -0
- package/utils/build-openssl.bat +13 -0
- package/utils/buildFlags.js +19 -0
- package/utils/configureLibssh2.js +54 -0
- package/utils/defaultCxxStandard.js +18 -0
- package/utils/execPromise.js +24 -0
- package/utils/getElectronOpenSSLRoot.js +10 -0
- package/utils/gitExecutableLocation.js +23 -0
- package/utils/isBuildingForElectron.js +30 -0
- package/utils/retry.js +51 -0
package/lib/tree.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
var path = require("path");
|
|
2
|
+
var events = require("events");
|
|
3
|
+
var NodeGit = require("../");
|
|
4
|
+
var Diff = NodeGit.Diff;
|
|
5
|
+
var LookupWrapper = NodeGit.Utils.lookupWrapper;
|
|
6
|
+
var Tree = NodeGit.Tree;
|
|
7
|
+
var Treebuilder = NodeGit.Treebuilder;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves the tree pointed to by the oid
|
|
11
|
+
* @async
|
|
12
|
+
* @param {Repository} repo The repo that the tree lives in
|
|
13
|
+
* @param {String|Oid|Tree} id The tree to lookup
|
|
14
|
+
* @return {Tree}
|
|
15
|
+
*/
|
|
16
|
+
Tree.lookup = LookupWrapper(Tree);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Make builder. This is helpful for modifying trees.
|
|
20
|
+
* @return {Treebuilder}
|
|
21
|
+
*/
|
|
22
|
+
Tree.prototype.builder = function() {
|
|
23
|
+
var builder = Treebuilder.create(this);
|
|
24
|
+
|
|
25
|
+
builder.root = builder;
|
|
26
|
+
builder.repo = this.repo;
|
|
27
|
+
|
|
28
|
+
return builder;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Diff two trees
|
|
33
|
+
* @async
|
|
34
|
+
* @param {Tree} tree to diff against
|
|
35
|
+
* @return {Diff}
|
|
36
|
+
*/
|
|
37
|
+
Tree.prototype.diff = function(tree) {
|
|
38
|
+
return this.diffWithOptions(tree, null);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Diff two trees with options
|
|
43
|
+
* @async
|
|
44
|
+
* @param {Tree} tree to diff against
|
|
45
|
+
* @param {Object} options
|
|
46
|
+
* @return {Diff}
|
|
47
|
+
*/
|
|
48
|
+
Tree.prototype.diffWithOptions = function(tree, options) {
|
|
49
|
+
return Diff.treeToTree(this.repo, tree, this, options);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Return an array of the entries in this tree (excluding its children).
|
|
54
|
+
* @return {Array<TreeEntry>} an array of TreeEntrys
|
|
55
|
+
*/
|
|
56
|
+
Tree.prototype.entries = function() {
|
|
57
|
+
var size = this.entryCount();
|
|
58
|
+
var result = [];
|
|
59
|
+
|
|
60
|
+
for (var i = 0; i < size; i++) {
|
|
61
|
+
result.push(this.entryByIndex(i));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return result;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Get an entry at the ith position.
|
|
69
|
+
*
|
|
70
|
+
* @param {Number} i
|
|
71
|
+
* @return {TreeEntry}
|
|
72
|
+
*/
|
|
73
|
+
Tree.prototype.entryByIndex = function(i) {
|
|
74
|
+
var entry = this._entryByIndex(i);
|
|
75
|
+
entry.parent = this;
|
|
76
|
+
return entry;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get an entry by name; if the tree is a directory, the name is the filename.
|
|
81
|
+
*
|
|
82
|
+
* @param {String} name
|
|
83
|
+
* @return {TreeEntry}
|
|
84
|
+
*/
|
|
85
|
+
Tree.prototype.entryByName = function(name) {
|
|
86
|
+
var entry = this._entryByName(name);
|
|
87
|
+
entry.parent = this;
|
|
88
|
+
return entry;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Get an entry at a path. Unlike by name, this takes a fully
|
|
93
|
+
* qualified path, like `/foo/bar/baz.javascript`
|
|
94
|
+
* @async
|
|
95
|
+
* @param {String} filePath
|
|
96
|
+
* @return {TreeEntry}
|
|
97
|
+
*/
|
|
98
|
+
Tree.prototype.getEntry = function(filePath) {
|
|
99
|
+
var tree = this;
|
|
100
|
+
|
|
101
|
+
return this.entryByPath(filePath).then(function(entry) {
|
|
102
|
+
entry.parent = tree;
|
|
103
|
+
entry.dirtoparent = path.dirname(filePath);
|
|
104
|
+
return entry;
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Return the path of this tree, like `/lib/foo/bar`
|
|
110
|
+
* @return {String}
|
|
111
|
+
*/
|
|
112
|
+
Tree.prototype.path = function(blobsOnly) {
|
|
113
|
+
return this.entry ? this.entry.path() : "";
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Recursively walk the tree in breadth-first order. Fires an event for each
|
|
118
|
+
* entry.
|
|
119
|
+
*
|
|
120
|
+
* @fires EventEmitter#entry Tree
|
|
121
|
+
* @fires EventEmitter#end Array<Tree>
|
|
122
|
+
* @fires EventEmitter#error Error
|
|
123
|
+
*
|
|
124
|
+
* @param {Boolean} [blobsOnly = true] True to emit only blob & blob executable
|
|
125
|
+
* entries.
|
|
126
|
+
*
|
|
127
|
+
* @return {EventEmitter}
|
|
128
|
+
*/
|
|
129
|
+
Tree.prototype.walk = function(blobsOnly) {
|
|
130
|
+
blobsOnly = typeof blobsOnly === "boolean" ? blobsOnly : true;
|
|
131
|
+
|
|
132
|
+
var self = this;
|
|
133
|
+
var event = new events.EventEmitter();
|
|
134
|
+
|
|
135
|
+
var total = 1;
|
|
136
|
+
var entries = new Set();
|
|
137
|
+
var finalEntires = [];
|
|
138
|
+
|
|
139
|
+
// This looks like a DFS, but it is a BFS because of implicit queueing in
|
|
140
|
+
// the recursive call to `entry.getTree(bfs)`
|
|
141
|
+
function bfs(error, tree) {
|
|
142
|
+
total--;
|
|
143
|
+
|
|
144
|
+
if (error) {
|
|
145
|
+
return event.emit("error", error);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
tree.entries().forEach(function (entry, entryIndex) {
|
|
149
|
+
if (!blobsOnly || entry.isFile() && !entries.has(entry)) {
|
|
150
|
+
event.emit("entry", entry);
|
|
151
|
+
entries.add(entry);
|
|
152
|
+
|
|
153
|
+
// Node 0.12 doesn't support either [v for (v of entries)] nor
|
|
154
|
+
// Array.from so we'll just maintain our own list.
|
|
155
|
+
finalEntires.push(entry);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (entry.isTree()) {
|
|
159
|
+
total++;
|
|
160
|
+
entry.getTree()
|
|
161
|
+
.then(result => bfs(null, result), bfs);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
if (total === 0) {
|
|
166
|
+
event.emit("end", finalEntires);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
event.start = function() {
|
|
171
|
+
bfs(null, self);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
return event;
|
|
175
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
var path = require("path").posix;
|
|
2
|
+
var NodeGit = require("../");
|
|
3
|
+
var TreeEntry = NodeGit.TreeEntry;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Retrieve the blob for this entry. Make sure to call `isBlob` first!
|
|
7
|
+
* @async
|
|
8
|
+
* @return {Blob}
|
|
9
|
+
*/
|
|
10
|
+
TreeEntry.prototype.getBlob = function() {
|
|
11
|
+
return this.parent.repo.getBlob(this.id());
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Retrieve the tree for this entry. Make sure to call `isTree` first!
|
|
16
|
+
* @async
|
|
17
|
+
* @return {Tree}
|
|
18
|
+
*/
|
|
19
|
+
TreeEntry.prototype.getTree = function() {
|
|
20
|
+
var entry = this;
|
|
21
|
+
|
|
22
|
+
return this.parent.repo.getTree(this.id()).then(function(tree) {
|
|
23
|
+
tree.entry = entry;
|
|
24
|
+
return tree;
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Is this TreeEntry a blob? Alias for `isFile`
|
|
30
|
+
* @return {Boolean}
|
|
31
|
+
*/
|
|
32
|
+
TreeEntry.prototype.isBlob = function() {
|
|
33
|
+
return this.isFile();
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Is this TreeEntry a directory? Alias for `isTree`
|
|
38
|
+
* @return {Boolean}
|
|
39
|
+
*/
|
|
40
|
+
TreeEntry.prototype.isDirectory = function() {
|
|
41
|
+
return this.isTree();
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Is this TreeEntry a blob? (i.e., a file)
|
|
46
|
+
* @return {Boolean}
|
|
47
|
+
*/
|
|
48
|
+
TreeEntry.prototype.isFile = function() {
|
|
49
|
+
return this.filemode() === TreeEntry.FILEMODE.BLOB ||
|
|
50
|
+
this.filemode() === TreeEntry.FILEMODE.EXECUTABLE;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Is this TreeEntry a submodule?
|
|
55
|
+
* @return {Boolean}
|
|
56
|
+
*/
|
|
57
|
+
TreeEntry.prototype.isSubmodule = function() {
|
|
58
|
+
return this.filemode() === TreeEntry.FILEMODE.COMMIT;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Is this TreeEntry a tree? (i.e., a directory)
|
|
63
|
+
* @return {Boolean}
|
|
64
|
+
*/
|
|
65
|
+
TreeEntry.prototype.isTree = function() {
|
|
66
|
+
return this.filemode() === TreeEntry.FILEMODE.TREE;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Retrieve the SHA for this TreeEntry. Alias for `sha`
|
|
71
|
+
* @return {String}
|
|
72
|
+
*/
|
|
73
|
+
TreeEntry.prototype.oid = function() {
|
|
74
|
+
return this.sha();
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Returns the path for this entry.
|
|
79
|
+
* @return {String}
|
|
80
|
+
*/
|
|
81
|
+
TreeEntry.prototype.path = function() {
|
|
82
|
+
var dirtoparent = this.dirtoparent || "";
|
|
83
|
+
return path.join(this.parent.path(), dirtoparent, this.name());
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Retrieve the SHA for this TreeEntry.
|
|
88
|
+
* @return {String}
|
|
89
|
+
*/
|
|
90
|
+
TreeEntry.prototype.sha = function() {
|
|
91
|
+
return this.id().toString();
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Alias for `path`
|
|
96
|
+
*/
|
|
97
|
+
TreeEntry.prototype.toString = function() {
|
|
98
|
+
return this.path();
|
|
99
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var NodeGit = require("../../");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Wraps a method so that you can pass in either a string, OID or the object
|
|
5
|
+
* itself and you will always get back a promise that resolves to the object.
|
|
6
|
+
* @param {Object} objectType The object type that you're expecting to receive.
|
|
7
|
+
* @param {Function} lookupFunction The function to do the lookup for the
|
|
8
|
+
* object. Defaults to `objectType.lookup`.
|
|
9
|
+
* @return {Function}
|
|
10
|
+
*/
|
|
11
|
+
function lookupWrapper(objectType, lookupFunction) {
|
|
12
|
+
lookupFunction = lookupFunction || objectType.lookup;
|
|
13
|
+
|
|
14
|
+
return function(repo, id, callback) {
|
|
15
|
+
if (id instanceof objectType) {
|
|
16
|
+
return Promise.resolve(id).then(function(obj) {
|
|
17
|
+
obj.repo = repo;
|
|
18
|
+
|
|
19
|
+
if (typeof callback === "function") {
|
|
20
|
+
callback(null, obj);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return obj;
|
|
24
|
+
}, callback);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return lookupFunction(repo, id).then(function(obj) {
|
|
28
|
+
obj.repo = repo;
|
|
29
|
+
|
|
30
|
+
if (typeof callback === "function") {
|
|
31
|
+
callback(null, obj);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return obj;
|
|
35
|
+
}, callback);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
NodeGit.Utils.lookupWrapper = lookupWrapper;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var NodeGit = require("../../");
|
|
2
|
+
|
|
3
|
+
function shallowClone() {
|
|
4
|
+
var merges = Array.prototype.slice.call(arguments);
|
|
5
|
+
|
|
6
|
+
return merges.reduce(function(obj, merge) {
|
|
7
|
+
return Object.keys(merge).reduce(function(obj, key) {
|
|
8
|
+
obj[key] = merge[key];
|
|
9
|
+
return obj;
|
|
10
|
+
}, obj);
|
|
11
|
+
}, {});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
NodeGit.Utils.shallowClone = shallowClone;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var buildFlags = require("../utils/buildFlags");
|
|
2
|
+
|
|
3
|
+
module.exports = async function install() {
|
|
4
|
+
console.log("[nodegit] Running install script");
|
|
5
|
+
|
|
6
|
+
var args = ["install"];
|
|
7
|
+
|
|
8
|
+
if (buildFlags.mustBuild) {
|
|
9
|
+
console.info(
|
|
10
|
+
"[nodegit] Pre-built download disabled, building from source.",
|
|
11
|
+
);
|
|
12
|
+
args.push("--build-from-source");
|
|
13
|
+
|
|
14
|
+
if (buildFlags.debugBuild) {
|
|
15
|
+
console.info("[nodegit] Building debug version.");
|
|
16
|
+
args.push("--debug");
|
|
17
|
+
}
|
|
18
|
+
} else {
|
|
19
|
+
args.push("--fallback-to-build");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// Called on the command line
|
|
26
|
+
if (require.main === module) {
|
|
27
|
+
module.exports().catch(function (e) {
|
|
28
|
+
console.error("[nodegit] ERROR - Could not finish install");
|
|
29
|
+
console.error("[nodegit] ERROR - finished with error code: " + e);
|
|
30
|
+
process.exit(e);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
var fse = require("fs-extra");
|
|
2
|
+
var path = require("path");
|
|
3
|
+
|
|
4
|
+
var exec = require("../utils/execPromise");
|
|
5
|
+
var buildFlags = require("../utils/buildFlags");
|
|
6
|
+
|
|
7
|
+
var rootPath = path.join(__dirname, "..");
|
|
8
|
+
|
|
9
|
+
function printStandardLibError() {
|
|
10
|
+
console.log(
|
|
11
|
+
"[nodegit] ERROR - the latest libstdc++ is missing on your system!"
|
|
12
|
+
);
|
|
13
|
+
console.log("");
|
|
14
|
+
console.log("On Ubuntu you can install it using:");
|
|
15
|
+
console.log("");
|
|
16
|
+
console.log("$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test");
|
|
17
|
+
console.log("$ sudo apt-get update");
|
|
18
|
+
console.log("$ sudo apt-get install libstdc++-4.9-dev");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = function install() {
|
|
22
|
+
if (buildFlags.isGitRepo) {
|
|
23
|
+
// If we're building NodeGit from a git repo we aren't going to do any
|
|
24
|
+
// cleaning up
|
|
25
|
+
return Promise.resolve();
|
|
26
|
+
}
|
|
27
|
+
if (buildFlags.isElectron || buildFlags.isNWjs) {
|
|
28
|
+
// If we're building for electron or NWjs, we're unable to require the
|
|
29
|
+
// built library so we have to just assume success, unfortunately.
|
|
30
|
+
return Promise.resolve();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return exec("node \"" + path.join(rootPath, "lib/nodegit.js\""))
|
|
34
|
+
.catch(function(e) {
|
|
35
|
+
if (~e.toString().indexOf("Module version mismatch")) {
|
|
36
|
+
console.warn(
|
|
37
|
+
"[nodegit] WARN - NodeGit was built for a different version of node."
|
|
38
|
+
);
|
|
39
|
+
console.warn(
|
|
40
|
+
"If you are building NodeGit for electron/nwjs you can " +
|
|
41
|
+
"ignore this warning."
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
throw e;
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
.then(function() {
|
|
49
|
+
// If we're using NodeGit from a package manager then let's clean up after
|
|
50
|
+
// ourselves when we install successfully.
|
|
51
|
+
if (!buildFlags.mustBuild) {
|
|
52
|
+
// We can't remove the source files yet because apparently the
|
|
53
|
+
// "standard workflow" for native node moduels in Electron/nwjs is to
|
|
54
|
+
// build them for node and then nah eff that noise let's rebuild them
|
|
55
|
+
// again for the actual platform! Hurray!!! When that madness is dead
|
|
56
|
+
// we can clean up the source which is a serious amount of data.
|
|
57
|
+
// fse.removeSync(path.join(rootPath, "vendor"));
|
|
58
|
+
// fse.removeSync(path.join(rootPath, "src"));
|
|
59
|
+
// fse.removeSync(path.join(rootPath, "include"));
|
|
60
|
+
|
|
61
|
+
fse.removeSync(path.join(rootPath, "build/Release/*.a"));
|
|
62
|
+
fse.removeSync(path.join(rootPath, "build/Release/obj.target"));
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// Called on the command line
|
|
68
|
+
if (require.main === module) {
|
|
69
|
+
module.exports()
|
|
70
|
+
.catch(function(e) {
|
|
71
|
+
console.warn("[nodegit] WARN - Could not finish postinstall");
|
|
72
|
+
|
|
73
|
+
if (
|
|
74
|
+
process.platform === "linux" &&
|
|
75
|
+
~e.toString().indexOf("libstdc++")
|
|
76
|
+
) {
|
|
77
|
+
printStandardLibError();
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
console.log(e);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
var path = require("path");
|
|
2
|
+
var local = path.join.bind(path, __dirname);
|
|
3
|
+
|
|
4
|
+
var exec = require(local("../utils/execPromise"));
|
|
5
|
+
var buildFlags = require(local("../utils/buildFlags"));
|
|
6
|
+
|
|
7
|
+
module.exports = function prepareForBuild() {
|
|
8
|
+
console.log("[nodegit] Running pre-install script");
|
|
9
|
+
|
|
10
|
+
return exec("npm -v")
|
|
11
|
+
.then(
|
|
12
|
+
function(npmVersion) {
|
|
13
|
+
if (npmVersion.split(".")[0] < 3) {
|
|
14
|
+
console.log(
|
|
15
|
+
"[nodegit] npm@2 installed, pre-loading required packages"
|
|
16
|
+
);
|
|
17
|
+
return exec("npm install --ignore-scripts");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return Promise.resolve();
|
|
21
|
+
},
|
|
22
|
+
function() {
|
|
23
|
+
// We're installing via yarn, so don't
|
|
24
|
+
// care about compability with npm@2
|
|
25
|
+
}
|
|
26
|
+
)
|
|
27
|
+
.then(function() {
|
|
28
|
+
if (buildFlags.isGitRepo) {
|
|
29
|
+
var submodules = require(local("submodules"));
|
|
30
|
+
var generate = require(local("../generate"));
|
|
31
|
+
return submodules()
|
|
32
|
+
.then(function() {
|
|
33
|
+
return generate();
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Called on the command line
|
|
40
|
+
if (require.main === module) {
|
|
41
|
+
module.exports()
|
|
42
|
+
.catch(function(e) {
|
|
43
|
+
console.error("[nodegit] ERROR - Could not finish preinstall");
|
|
44
|
+
console.error(e);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
if (!stdout) {
|
|
9
|
+
// In the case where we pull from npm they pre-init the submodules for
|
|
10
|
+
// us and `git submodule status` returns empty-string. In that case
|
|
11
|
+
// we'll just assume that we're good.
|
|
12
|
+
return Promise.resolve([]);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getStatusPromiseFromLine(line) {
|
|
16
|
+
var lineSections = line.trim().split(" ");
|
|
17
|
+
var onNewCommit = !!~lineSections[0].indexOf("+");
|
|
18
|
+
var needsInitialization = !!~lineSections[0].indexOf("-");
|
|
19
|
+
var commitOid = lineSections[0].replace("+", "").replace("-", "");
|
|
20
|
+
var name = lineSections[1];
|
|
21
|
+
|
|
22
|
+
return exec("git status", { cwd: path.join(rootDir, name) }).then(
|
|
23
|
+
function (workDirStatus) {
|
|
24
|
+
return {
|
|
25
|
+
commitOid: commitOid,
|
|
26
|
+
onNewCommit: onNewCommit,
|
|
27
|
+
name: name,
|
|
28
|
+
needsInitialization: needsInitialization,
|
|
29
|
+
workDirDirty: !~workDirStatus
|
|
30
|
+
.trim()
|
|
31
|
+
.split("\n")
|
|
32
|
+
.pop()
|
|
33
|
+
.indexOf("nothing to commit"),
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return Promise.all(
|
|
40
|
+
stdout.trim().split("\n").map(getStatusPromiseFromLine),
|
|
41
|
+
);
|
|
42
|
+
})
|
|
43
|
+
.catch(function (err) {
|
|
44
|
+
console.error("[readme] failure to get submodule status:", err);
|
|
45
|
+
// In the case that NodeGit is required from another project via npm we
|
|
46
|
+
// won't be able to run submodule commands but that's ok since the
|
|
47
|
+
// correct version of libgit2 is published with nodegit.
|
|
48
|
+
return Promise.resolve([]);
|
|
49
|
+
});
|
|
50
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
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.error(
|
|
15
|
+
"[nodegit] ERROR - Compilation of NodeGit requires git " +
|
|
16
|
+
"CLI to be installed and on the path",
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
throw new Error("git CLI is not installed or not on the path");
|
|
20
|
+
})
|
|
21
|
+
.then(function () {
|
|
22
|
+
console.log("[nodegit] Checking submodule status");
|
|
23
|
+
return submoduleStatus();
|
|
24
|
+
})
|
|
25
|
+
.then(function (statuses) {
|
|
26
|
+
console.log("[readme] submodule status: ", statuses);
|
|
27
|
+
function printSubmodule(submoduleName) {
|
|
28
|
+
console.log("\t" + submoduleName);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var dirtySubmodules = statuses
|
|
32
|
+
.filter(function (status) {
|
|
33
|
+
return status.workDirDirty && !status.needsInitialization;
|
|
34
|
+
})
|
|
35
|
+
.map(function (dirtySubmodule) {
|
|
36
|
+
return dirtySubmodule.name;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
if (dirtySubmodules.length) {
|
|
40
|
+
console.error(
|
|
41
|
+
"[nodegit] ERROR - Some submodules have uncommited changes:",
|
|
42
|
+
);
|
|
43
|
+
dirtySubmodules.forEach(printSubmodule);
|
|
44
|
+
console.error(
|
|
45
|
+
"\nThey must either be committed or discarded before we build",
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
throw new Error("Dirty Submodules: " + dirtySubmodules.join(" "));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
var outOfSyncSubmodules = statuses
|
|
52
|
+
.filter(function (status) {
|
|
53
|
+
return status.onNewCommit && !status.needsInitialization;
|
|
54
|
+
})
|
|
55
|
+
.map(function (outOfSyncSubmodule) {
|
|
56
|
+
return outOfSyncSubmodule.name;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
if (outOfSyncSubmodules.length) {
|
|
60
|
+
console.warn(
|
|
61
|
+
"[nodegit] WARNING - Some submodules are pointing to an new commit:",
|
|
62
|
+
);
|
|
63
|
+
outOfSyncSubmodules.forEach(printSubmodule);
|
|
64
|
+
console.warn("\nThey will not be updated.");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return statuses
|
|
68
|
+
.filter(function (status) {
|
|
69
|
+
return !status.onNewCommit;
|
|
70
|
+
})
|
|
71
|
+
.reduce(function (chainPromise, submoduleToUpdate) {
|
|
72
|
+
return chainPromise.then(function () {
|
|
73
|
+
console.log(
|
|
74
|
+
"[nodegit] Initializing submodule",
|
|
75
|
+
submoduleToUpdate.name,
|
|
76
|
+
);
|
|
77
|
+
return exec(
|
|
78
|
+
"git submodule update --init --recursive " +
|
|
79
|
+
submoduleToUpdate.name,
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
}, Promise.resolve());
|
|
83
|
+
});
|
|
84
|
+
};
|