@ebuka_dev/git-branch-cleaner
Version:
A CLI tool to help manage and clean up Git branches
42 lines (41 loc) • 1.38 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.gitService = exports.GitService = void 0;
const simple_git_1 = __importDefault(require("simple-git"));
class GitService {
constructor() {
this.git = (0, simple_git_1.default)();
}
async getAllBranches() {
return await this.git.branch(["-vv"]);
}
async getMergedBranches() {
return await this.git.branch(["--merged"]);
}
async getRemoteBranches() {
return await this.git.branch(["-r"]);
}
async deleteLocalBranch(name, force = false) {
return await this.git.deleteLocalBranch(name, force);
}
async deleteRemoteBranch(name) {
return await this.git.push("origin", `:${name}`);
}
async getDeletableBranches() {
const branches = await this.getAllBranches();
return Object.entries(branches.branches)
.filter(([name, branch]) => name !== 'master' &&
name !== 'main' &&
!branch.current)
.map(([name, branch]) => ({
name,
label: branch.label,
current: branch.current
}));
}
}
exports.GitService = GitService;
exports.gitService = new GitService();