branchforge
Advanced tools
Comparing version 0.9.0 to 0.10.0
@@ -46,8 +46,9 @@ #!/usr/bin/env node | ||
class GitService { | ||
constructor() { | ||
constructor(force) { | ||
this.git = (0, simple_git_1.default)(); | ||
this.force = force; | ||
} | ||
fetch() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const output = yield this.git.fetch(); | ||
yield this.git.fetch(); | ||
}); | ||
@@ -97,3 +98,5 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.git.branch(["-D", branchName]); | ||
if (this.force) { | ||
yield this.git.branch(["-D", branchName]); | ||
} | ||
console.log(`Deleted branch "${branchName}".`); | ||
@@ -105,15 +108,17 @@ }); | ||
console.log(`Rebuilding branch "${branchName}" from base "${base}" and includes: ${includes.join(", ")}.`); | ||
yield this.git.checkout(base); | ||
yield this.git.checkoutLocalBranch(branchName); | ||
for (const include of includes) { | ||
const includeBranch = (yield this.branchExists(include)) | ||
? include | ||
: `origin/${include}`; | ||
try { | ||
yield this.git.merge([includeBranch]); | ||
} | ||
catch (error) { | ||
if (error instanceof Error) { | ||
console.error(`Error merging branch "${includeBranch}": ${error.message}`); | ||
if (this.force) { | ||
yield this.git.checkout(base); | ||
yield this.git.checkoutLocalBranch(branchName); | ||
for (const include of includes) { | ||
const includeBranch = (yield this.branchExists(include)) | ||
? include | ||
: `origin/${include}`; | ||
try { | ||
yield this.git.merge([includeBranch]); | ||
} | ||
catch (error) { | ||
if (error instanceof Error) { | ||
console.error(`Error merging branch "${includeBranch}": ${error.message}`); | ||
} | ||
} | ||
} | ||
@@ -154,3 +159,5 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.git.checkout(branch); | ||
if (this.force) { | ||
yield this.git.checkout(branch); | ||
} | ||
console.log(`Checked out branch "${branch}".`); | ||
@@ -177,3 +184,3 @@ }); | ||
// Rebuild the branch if it doesn't match the spec or is behind | ||
const rebuildBranch = (branchName, spec, gitService, force) => __awaiter(void 0, void 0, void 0, function* () { | ||
const rebuildBranch = (branchName, spec, gitService) => __awaiter(void 0, void 0, void 0, function* () { | ||
const branchConfig = spec.branches[branchName]; | ||
@@ -210,5 +217,3 @@ if (!branchConfig) { | ||
console.log(`Branch "${branchName}" does not exist, creating it.`); | ||
if (force) { | ||
yield gitService.recreateBranch(base, branchName, includes); | ||
} | ||
yield gitService.recreateBranch(base, branchName, includes); | ||
return; | ||
@@ -219,6 +224,4 @@ } | ||
console.log(`Branch "${branchName}" differs from "${base}" + [${includes.join(", ")}], rebuilding.`); | ||
if (force) { | ||
yield gitService.deleteBranch(branchName); | ||
yield gitService.recreateBranch(base, branchName, includes); | ||
} | ||
yield gitService.deleteBranch(branchName); | ||
yield gitService.recreateBranch(base, branchName, includes); | ||
} | ||
@@ -231,6 +234,2 @@ else { | ||
const runCLI = () => __awaiter(void 0, void 0, void 0, function* () { | ||
const gitService = new GitService(); | ||
yield gitService.fetch(); // Fetch all remote branches before proceeding | ||
const originalBranch = yield gitService.getCurrentBranch(); // Use the new method | ||
console.log("starting out in branch", originalBranch); | ||
commander_1.program | ||
@@ -242,2 +241,9 @@ .version("1.0.0") | ||
.action((branch, options) => __awaiter(void 0, void 0, void 0, function* () { | ||
if (!options.force) { | ||
console.log("DRY RUN, no actions will be performed."); | ||
} | ||
const gitService = new GitService(options.force); | ||
yield gitService.fetch(); // Fetch all remote branches before proceeding | ||
const originalBranch = yield gitService.getCurrentBranch(); // Use the new method | ||
console.log("starting out in branch", originalBranch); | ||
console.log("OPTIONS", options); | ||
@@ -255,7 +261,7 @@ const yamlFiles = [ | ||
if (branch) { | ||
yield rebuildBranch(branch, spec, gitService, options.force); | ||
yield rebuildBranch(branch, spec, gitService); | ||
} | ||
else { | ||
for (const branchName of Object.keys(spec.branches)) { | ||
yield rebuildBranch(branchName, spec, gitService, options.force); | ||
yield rebuildBranch(branchName, spec, gitService); | ||
} | ||
@@ -262,0 +268,0 @@ } |
{ | ||
"name": "branchforge", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
12402
272