-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitcheck.js
executable file
·78 lines (72 loc) · 2.42 KB
/
gitcheck.js
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env node
var fs = require("fs");
var path = require("path");
var gitrunner = require("gitrunner").Async;
var check = function(folder, onupdate, oncompleted) {
function checkSubfolders() {
fs.readdir(folder, function(err, files) {
(function loopfn(i, completed) {
if (!(i < files.length)) {
if (completed) completed();
return;
}
var fp = path.resolve(folder, files[i]);
fs.stat(fp, function(err, stat) {
if (stat.isDirectory()) {
check(fp, onupdate, function() {
loopfn(i + 1, completed);
});
} else {
loopfn(i + 1, completed);
}
});
})(0, oncompleted);
});
}
if (fs.existsSync(path.resolve(folder, ".git"))) {
gitrunner.fullStatus(folder, function(err, status) {
if (err) {
console.log("error checking " + folder);
console.log(err);
}
if (status.isRepo) {
onupdate(status),
oncompleted();
} else {
// not a git repo - check subfolders
checkSubfolders();
}
});
} else {
checkSubfolders();
}
};
check(process.cwd(),
function(folder) {
var relpath = path.relative(process.cwd(), folder.path) || ".";
if (folder.changedFiles.length == 1) {
console.log("1 changed file in " + relpath);
return;
}
if (folder.changedFiles.length > 1) {
console.log(folder.changedFiles.length + " changed files in " + relpath);
return;
}
if (folder.unpushedCommits.length == 1) {
console.log("1 unpushed commit in " + relpath);
}
if (folder.unpushedCommits.length > 1) {
console.log(folder.unpushedCommits.length + " unpushed commits in " + relpath);
}
if (!folder.branch) {
console.log("No branch set for " + relpath);
return;
}
if (!folder.remoteBranch) {
console.log("No remote branch for " + relpath);
}
},
function() {
console.log("completed check");
// todo: fire update for any missing folders in knownfolders
});