forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetStatus.js
More file actions
50 lines (46 loc) · 1.72 KB
/
getStatus.js
File metadata and controls
50 lines (46 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var path = require("path");
var rootDir = path.join(__dirname, "../..");
var exec = require(path.join(rootDir, "./utils/execPromise"));
module.exports = function getStatus() {
return exec("git submodule status", { cwd: rootDir})
.then(function(stdout) {
if (!stdout) {
// In the case where we pull from npm they pre-init the submodules for
// us and `git submodule status` returns empty-string. In that case
// we'll just assume that we're good.
return Promise.resolve([]);
}
function getStatusPromiseFromLine(line) {
var lineSections = line.trim().split(" ");
var onNewCommit = !!~lineSections[0].indexOf("+");
var needsInitialization = !!~lineSections[0].indexOf("-");
var commitOid = lineSections[0].replace("+", "").replace("-", "");
var name = lineSections[1];
return exec("git status", { cwd: path.join(rootDir, name)})
.then(function(workDirStatus) {
return {
commitOid: commitOid,
onNewCommit: onNewCommit,
name: name,
needsInitialization: needsInitialization,
workDirDirty: !~workDirStatus
.trim()
.split("\n")
.pop()
.indexOf("nothing to commit")
};
});
}
return Promise.all(stdout
.trim()
.split("\n")
.map(getStatusPromiseFromLine)
);
})
.catch(function() {
// In the case that NodeGit is required from another project via npm we
// won't be able to run submodule commands but that's ok since the
// correct version of libgit2 is published with nodegit.
return Promise.resolve([]);
});
};