feat: add 'undo' option to version command

This commit is contained in:
s41r4j
2026-01-29 00:35:46 +05:30
parent bd906885c2
commit 00217a6ac7
3 changed files with 45 additions and 1 deletions
+1
View File
@@ -791,6 +791,7 @@ program.command('version').alias('v')
.option('--list', 'List S4 tags (hides dev tags by default)')
.option('--prune', 'Prune old dev tags (keeps last 10)')
.option('--all', 'Show all tags (including dev) when listing')
.option('-u, --undo', 'Undo the last version bump (delete latest tag)')
.action(async (type, options) => {
await ensureRepo();
if (!versionCmd) initializeComponents();
+43
View File
@@ -26,6 +26,11 @@ class VersionCommand {
return;
}
if (options.undo) {
await this.undoLastBump();
return;
}
// --- Main Bump Logic ---
// 1. Get current version from Git Tags (SSOT)
@@ -196,6 +201,44 @@ class VersionCommand {
console.log(color.dim('Kept last 10 dev tags + all stable tags.'));
}
async undoLastBump() {
Progress.start('Undoing last version bump...');
// 1. Get current version (the one to delete)
const currentVersion = await this.s4.getCurrentVersion();
if (!currentVersion) {
Progress.stop('');
console.log(color.yellow('No S4 version tags found to undo.'));
return;
}
// 2. Delete the tag
try {
await this.git.tag(['-d', currentVersion]);
Progress.stop('');
console.log(`${color.green('✔')} Deleted tag: ${color.cyan(currentVersion)}`);
} catch (e) {
Progress.error(`Failed to delete tag: ${e.message}`);
return;
}
// 3. Revert .env files to *previous* version
// Now that the latest tag is gone, getCurrentVersion will return the previous one
const previousVersion = await this.s4.getCurrentVersion() || '0.0.0';
if (previousVersion) {
console.log(`Reverting environment to previous version: ${color.dim(previousVersion)}`);
const updatedFiles = this.updateEnvFiles(previousVersion);
if (updatedFiles.length > 0) {
console.log(`${color.green('✔')} Updated ${updatedFiles.join(', ')}`);
}
}
console.log(color.dim('\nNote: If you already pushed the tag, you must verify deletion on remote:'));
console.log(` ${color.cyan(`git push --delete origin ${currentVersion}`)}`);
}
showInfo(versionStr) {
const parsed = S4Versioning.parse(versionStr);
if (!parsed) {