@ebuka_dev/git-branch-cleaner
Version:
A CLI tool to help manage and clean up Git branches
42 lines (41 loc) • 1.9 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.listMergedBranches = listMergedBranches;
const GitService_1 = require("../services/GitService");
const spinner_1 = require("../utils/spinner");
const console_1 = require("../utils/console");
const prompt_1 = require("../utils/prompt");
const chalk_1 = __importDefault(require("chalk"));
const delete_1 = require("./delete");
async function listMergedBranches(verbose, autoDelete) {
spinner_1.spinner.start("Fetching merged branches...");
try {
const mergedBranches = await GitService_1.gitService.getMergedBranches();
const currentBranch = mergedBranches.current;
spinner_1.spinner.stop();
const branchesToDelete = Object.entries(mergedBranches.branches).filter(([name]) => name !== 'master' &&
name !== 'main' &&
name !== currentBranch);
if (branchesToDelete.length === 0) {
(0, console_1.logSuccess)("No merged branches found to clean up!");
return;
}
(0, console_1.logWarning)("Merged branches that can be deleted:");
branchesToDelete.forEach(([name, branch]) => {
console.log(` - ${chalk_1.default.cyan(name)}`);
if (verbose) {
console.log(` Last commit: ${chalk_1.default.gray(branch.label)}`);
}
});
if (autoDelete || await (0, prompt_1.confirmDelete)(branchesToDelete.map(([name]) => name))) {
await (0, delete_1.deleteStaleBranches)(branchesToDelete.map(([name]) => name));
}
}
catch (error) {
spinner_1.spinner.fail("Failed to fetch merged branches!");
(0, console_1.logError)("Error fetching merged branches:", error);
}
}