feat(commands): add --amend option to commit sub-command
This commit is contained in:
28
src/index.ts
28
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
|
||||
|
||||
Reference in New Issue
Block a user