feat(commands): add --amend option to commit sub-command

This commit is contained in:
2023-08-22 17:43:30 +03:00
parent 5080d71fb8
commit 92f8126abf

View File

@@ -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,7 +65,9 @@ program
process.exit(0);
}
const stageAll = await confirm({
const stageAll = amend
? null
: await confirm({
message: "Stage all changes?",
initialValue: true,
});
@@ -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