-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (33 loc) · 1020 Bytes
/
index.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
import currentBranch from 'current-git-branch';
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 gitNeedsPush = (altPath = cwd) => {
const thisPath = pathIsAbsolute(altPath) ? altPath : path.join(cwd, altPath);
if (!isGit(thisPath)) {
return false;
}
try {
let exec;
if (platform() === 'win32') {
exec = execa.shellSync(`pushd ${thisPath} & git push --dry-run --no-verify`);
} else {
exec = execa.shellSync(`(cd ${thisPath} ; git push --dry-run --no-verify)`);
}
// check if the current branch will be in the git output
if (exec.stderr.match('up-to-date')) {
return false;
}
return true;
} catch (e) {
// check if the current branch will be in the git output
if (e.message.match(currentBranch(thisPath))) {
return true;
}
return false;
}
};
export default gitNeedsPush;