-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
35 lines (26 loc) · 743 Bytes
/
index.js
File metadata and controls
35 lines (26 loc) · 743 Bytes
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
import execa from 'execa';
import isGit from 'is-git-repository';
import { platform } from 'os';
import path from 'path';
import pathIsAbsolute from 'path-is-absolute';
const cwd = process.cwd();
const commitCount = (altPath = cwd) => {
let count = 0;
let obj = {};
const thisPath = pathIsAbsolute(altPath) ? altPath : path.join(cwd, altPath);
if (!isGit(thisPath)) {
return -1;
}
try {
if (platform() === 'win32') {
obj = execa.shellSync(`pushd ${thisPath} & git rev-list --all --count`);
} else {
obj = execa.shellSync(`(cd ${thisPath} ; git rev-list --all --count)`);
}
count = parseInt(obj.stdout, 10);
return count;
} catch (e) {
return 0;
}
};
export default commitCount;