Skip to content

Commit 218d327

Browse files
committed
🐛 Fix: support for windows
1 parent a22961e commit 218d327

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

index.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
1-
import { platform } from 'os';
21
import execa from 'execa';
2+
import isGit from 'is-git-repository';
3+
import { platform } from 'os';
4+
import path from 'path';
5+
import pathIsAbsolute from 'path-is-absolute';
6+
37

48
const cwd = process.cwd();
59

610
const commitCount = (altPath = cwd) => {
711
let count = 0;
812
let obj = {};
913

14+
const thisPath = pathIsAbsolute(altPath) ? altPath : path.join(cwd, altPath);
15+
16+
if (!isGit(thisPath)) {
17+
return -1;
18+
}
19+
1020
try {
1121
if (platform() === 'win32') {
12-
obj = execa.shellSync(`pushd ${altPath} & git rev-list --all --count`);
22+
obj = execa.shellSync(`pushd ${thisPath} & git rev-list --all --count`);
1323
} else {
14-
obj = execa.shellSync(`(cd ${altPath} ; git rev-list --all --count)`);
24+
obj = execa.shellSync(`(cd ${thisPath} ; git rev-list --all --count)`);
1525
}
1626

1727
count = parseInt(obj.stdout, 10);
1828

1929
return count;
2030
} catch (e) {
21-
const error = e.toString().substring(0, 12);
22-
23-
if (error === 'Error: usage') {
24-
return count;
25-
}
26-
27-
return -1;
31+
return 0;
2832
}
2933
};
3034

0 commit comments

Comments
 (0)