From 92f8126abfa3a3a077acf633f7265f55ebc4f49c Mon Sep 17 00:00:00 2001 From: Olivers Vitins Date: Tue, 22 Aug 2023 17:43:30 +0300 Subject: [PATCH] feat(commands): add --amend option to commit sub-command --- src/index.ts | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index b6549db..55e0118 100644 --- a/src/index.ts +++ b/src/index.ts @@ -51,8 +51,10 @@ program .command("commit") .description("Create a conventional commit") .option("-S, --sign", "sign the commit") + .option("--amend", "amend commit message to the last commit") .action(async (options) => { const sign = options.sign ? true : false; + const amend = options.amend ? true : false; const config = await GetConfig(); @@ -63,10 +65,12 @@ program process.exit(0); } - const stageAll = await confirm({ - message: "Stage all changes?", - initialValue: true, - }); + const stageAll = amend + ? null + : await confirm({ + message: "Stage all changes?", + initialValue: true, + }); if (isCancel(stageAll)) { cancel("Commit creation cancelled"); @@ -204,14 +208,24 @@ program if (stageAll) { await simpleGit() .add(".") - .commit(commitMessage, sign ? ["-S"] : []); + .commit( + commitMessage, + sign ? (amend ? ["-S", "--amend"] : ["-S"]) : amend ? ["--amend"] : [] + ); } else { - await simpleGit().commit(commitMessage, sign ? ["-S"] : []); + await simpleGit().commit( + commitMessage, + sign ? (amend ? ["-S", "--amend"] : ["-S"]) : amend ? ["--amend"] : [] + ); } note(commitMessage); - outro("Finished creating a conventional commit, feel free to push"); + outro( + `Finished ${ + amend ? "amending" : "creating" + } a conventional commit, feel free to push` + ); }); program