@eljs/utils
Version:
Collection of nodejs utility.
72 lines (70 loc) • 2.37 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/git/is.ts
var is_exports = {};
__export(is_exports, {
isGitAheadRemote: () => isGitAheadRemote,
isGitBehindRemote: () => isGitBehindRemote,
isGitClean: () => isGitClean
});
module.exports = __toCommonJS(is_exports);
var import_cp = require("../cp");
async function isGitClean(options) {
try {
const rawStatus = await (0, import_cp.run)("git", ["status", "--porcelain"], options);
return rawStatus.stdout.trim().length === 0;
} catch (err) {
return false;
}
}
async function isGitBehindRemote(options) {
return (0, import_cp.run)("git", ["fetch"], {
...options,
verbose: false
}).then(() => {
return (0, import_cp.run)(
"git",
["status", "--porcelain", "-b", "-u", "--null"],
options
).then((data) => {
const behindResult = /\[(behind|落后)\s+(\d+)\]/.exec(data.stdout);
return (behindResult == null ? void 0 : behindResult[2]) ? Number(behindResult[2]) > 0 : false;
});
});
}
async function isGitAheadRemote(options) {
return (0, import_cp.run)("git", ["fetch"], {
...options,
verbose: false
}).then(() => {
return (0, import_cp.run)(
"git",
["status", "--porcelain", "-b", "-u", "--null"],
options
).then((data) => {
const aheadResult = /\[(ahead|超前)\s+(\d+)\]/.exec(data.stdout);
return (aheadResult == null ? void 0 : aheadResult[2]) ? Number(aheadResult[2]) > 0 : false;
});
});
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
isGitAheadRemote,
isGitBehindRemote,
isGitClean
});