UNPKG

1.36 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const execa = require("execa");
4// git checks logic is from https://github.com/sindresorhus/np/blob/master/source/git-tasks.js
5async function isGitRepo() {
6 try {
7 await execa('git', ['rev-parse', '--git-dir']);
8 }
9 catch (_) {
10 return false;
11 }
12 return true;
13}
14exports.isGitRepo = isGitRepo;
15async function getCurrentBranch() {
16 const { stdout } = await execa('git', ['symbolic-ref', '--short', 'HEAD']);
17 return stdout;
18}
19exports.getCurrentBranch = getCurrentBranch;
20async function isWorkingTreeClean() {
21 try {
22 const { stdout: status } = await execa('git', ['status', '--porcelain']);
23 if (status !== '') {
24 return false;
25 }
26 return true;
27 }
28 catch (_) {
29 return false;
30 }
31}
32exports.isWorkingTreeClean = isWorkingTreeClean;
33async function isRemoteHistoryClean() {
34 let history;
35 try { // Gracefully handle no remote set up.
36 const { stdout } = await execa('git', ['rev-list', '--count', '--left-only', '@{u}...HEAD']);
37 history = stdout;
38 }
39 catch (_) {
40 history = null;
41 }
42 if (history && history !== '0') {
43 return false;
44 }
45 return true;
46}
47exports.isRemoteHistoryClean = isRemoteHistoryClean;
48//# sourceMappingURL=gitChecks.js.map
\No newline at end of file