@copado/copado-cli
Version:
Copado Developer CLI
43 lines • 1.75 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Git = void 0;
const core_1 = require("@salesforce/core");
const simple_git_1 = __importDefault(require("simple-git"));
const child_process_1 = require("child_process");
const git = (0, simple_git_1.default)();
core_1.Messages.importMessagesDirectory(__dirname);
const messages = core_1.Messages.loadMessages('@copado/copado-cli', 'copado_work');
class Git {
static async checkoutBranches(baseBranch, branch) {
const branches = await git.branchLocal();
const userStoryName = branch.substring(branch.indexOf('/') + 1);
if (!branches.all.includes(baseBranch)) {
throw new core_1.SfError(`${messages.getMessage('errorNoBaseBranch')} ${userStoryName} is.`);
}
if (!branches.all.includes(branch)) {
await git.checkout(baseBranch);
await git.pull(`origin/${baseBranch}`);
await git.checkoutLocalBranch(branch);
}
else if (branches.current !== branch) {
await git.checkout(branch);
}
}
static async checkUnCommitedWork() {
return await git.status().then(status => {
return status.isClean();
});
}
static getProjectRoot() {
return (0, child_process_1.execSync)('git rev-parse --show-toplevel').toString().trim();
}
static isGitProjectRoot() {
const projectRoot = [this.getProjectRoot(), this.getProjectRoot().replace(/\//g, '\\')];
return projectRoot.includes(process.cwd());
}
}
exports.Git = Git;
//# sourceMappingURL=git.js.map