fix(commands): commit crash upon missing HEAD (#19)
This commit is contained in:
@@ -69,28 +69,32 @@ const command = new Command("commit")
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const changedLines = (
|
try {
|
||||||
(
|
const changedLines = (
|
||||||
await simpleGit().diff(["--numstat", stageAll ? "HEAD" : "--cached"])
|
(
|
||||||
).match(/\d+/gm) || []
|
await simpleGit().diff(["--numstat", stageAll ? "HEAD" : "--cached"])
|
||||||
).reduce((partialSum, num) => partialSum + Number(num), 0);
|
).match(/\d+/gm) || []
|
||||||
|
).reduce((partialSum, num) => partialSum + Number(num), 0);
|
||||||
|
|
||||||
if (changedLines > 250 && !sudo) {
|
if (changedLines > 250 && !sudo) {
|
||||||
const proceedCommitting = await confirm({
|
const proceedCommitting = await confirm({
|
||||||
message:
|
message:
|
||||||
"You are about to commit changes to more than 250 lines, are you sure you want to proceed?",
|
"You are about to commit changes to more than 250 lines, are you sure you want to proceed?",
|
||||||
initialValue: false,
|
initialValue: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isCancel(proceedCommitting)) {
|
if (isCancel(proceedCommitting)) {
|
||||||
cancel("Commit creation cancelled");
|
cancel("Commit creation cancelled");
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!proceedCommitting) {
|
if (!proceedCommitting) {
|
||||||
cancel("Cancelled, please split this commit into smaller ones");
|
cancel("Cancelled, please split this commit into smaller ones");
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
note("HEAD hasn't been found, skipping commit line amount check");
|
||||||
}
|
}
|
||||||
|
|
||||||
const type: string | symbol = await select({
|
const type: string | symbol = await select({
|
||||||
|
|||||||
Reference in New Issue
Block a user