From 00217a6ac7812ccde69456cdada02cc23dc977e3 Mon Sep 17 00:00:00 2001 From: s41r4j Date: Thu, 29 Jan 2026 00:35:46 +0530 Subject: [PATCH] feat: add 'undo' option to version command --- bin/gims.js | 1 + bin/lib/commands/version.js | 43 +++++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/bin/gims.js b/bin/gims.js index 1fa4e41..e67d0a0 100755 --- a/bin/gims.js +++ b/bin/gims.js @@ -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(); diff --git a/bin/lib/commands/version.js b/bin/lib/commands/version.js index 4c85e1f..f18eca2 100644 --- a/bin/lib/commands/version.js +++ b/bin/lib/commands/version.js @@ -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) { diff --git a/package.json b/package.json index 221578d..1963bf4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gims", - "version": "0.8.4", + "version": "0.8.5", "description": "Git Made Simple – AI‑powered git helper with smart insights, stats & code review", "author": "S41R4J", "license": "MIT",