@nu-art/commando
Version:
126 lines (125 loc) • 4.59 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Commando_Git = void 0;
const programming_1 = require("./programming");
const basic_1 = require("./basic");
const class_merger_1 = require("../core/class-merger");
const BaseCommando_1 = require("../core/BaseCommando");
const Super = (0, class_merger_1.MergeClass)(BaseCommando_1.BaseCommando, programming_1.Commando_Programming, basic_1.Commando_Basic);
class Commando_Git extends Super {
constructor() {
super(...arguments);
this.git = {
clone: this.git_clone,
checkout: this.git_checkout,
createTag: this.git_createTag,
gitCommit: this.git_gitCommit,
add: this.git_add,
addAll: this.git_addAll,
addAndCommit: this.git_addAndCommit,
push: this.git_push,
pushTags: this.git_pushTags,
fetch: this.git_fetch,
resetHard: this.git_resetHard,
getCurrentBranch: this.git_getCurrentBranch,
pull: this.git_pull,
merge: this.git_merge,
createBranch: this.git_createBranch,
gsui: this.git_gsui,
status: this.git_status,
};
}
git_clone(url, options) {
const branch = `${(options === null || options === void 0 ? void 0 : options.branch) ? ` -b ${options === null || options === void 0 ? void 0 : options.branch}` : ''}`;
const recursive = `${(options === null || options === void 0 ? void 0 : options.recursive) ? ` --recursive` : ''}`;
const outputFolder = `${(options === null || options === void 0 ? void 0 : options.outputFolder) ? ` ${options.outputFolder}` : ''}`;
const command = `git clone${recursive}${branch} ${url}${outputFolder}`;
this.append(command);
return this;
}
// git_cloneAssert(url: string, options?: GitCloneParams) {
// return new Promise<void>((resolve, reject) => {
// const branch = `${options?.branch ? ` -b ${options?.branch}` : ''}`;
// const recursive = `${options?.recursive ? ` --recursive` : ''}`;
// const outputFolder = `${options?.outputFolder ? ` ${options.outputFolder}` : ''}`;
// const command = `git clone${recursive}${branch} ${url}${outputFolder}`;
// this.echo(command);
// this.append(command)
// .execute((stdout: string, stderr: string, exitCode: number) => {
// if (exitCode === 0)
// return resolve();
//
// if (exitCode === 128)
// return reject(new Error(`No access to repo: ${url}`));
//
// return reject(new Error(`Got unexpected exit code(${exitCode}) while cloning: ${url}`));
// });
// });
// }
git_checkout(branch) {
this.append(`git checkout ${branch}`);
return this;
}
git_createTag(tagName) {
this.append(`git tag -f ${tagName}`);
return this;
}
git_gitCommit(commitMessage) {
this.append(`git commit -m "${commitMessage}"`);
return this;
}
git_add(file) {
this.append(`git add "${file}"`);
return this;
}
git_addAll() {
this.append(`git add .`);
return this;
}
git_addAndCommit(commitMessage) {
this.append(`git commit -am "${commitMessage}"`);
return this;
}
git_push(options) {
this.append(`git push ${options === null || options === void 0 ? void 0 : options.remote} ${options === null || options === void 0 ? void 0 : options.branch}`);
return this;
}
git_pushTags() {
this.append('git push --tags --force');
return this;
}
git_fetch() {
this.append('git fetch');
return this;
}
git_resetHard(tag = '') {
this.append('git reset --hard ${tag}');
return this;
}
git_getCurrentBranch() {
this.append('git status | grep "On branch" | sed -E "s');
return this;
}
git_pull(params) {
this.append('git pull ${params}');
return this;
}
git_merge(mergeFrom) {
this.append(`git merge ${mergeFrom}`);
return this;
}
git_createBranch(branch) {
this.append(`git checkout - b ${branch}`);
this.append(`git push-- set -upstream origin ${branch}`);
return this;
}
git_gsui(modules = '') {
this.append('git submodule update --recursive --init ${modules}');
return this;
}
git_status() {
this.append('git status');
return this;
}
}
exports.Commando_Git = Commando_Git;