Skip to content

Commit 24ce220

Browse files
committed
✨ feat: add checks for commit
1 parent 0fc17fb commit 24ce220

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/cli.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,38 @@ async function cli() {
3535
.then((answer) => {
3636
const message = `${answer.type}: ${answer.message}`;
3737

38+
if (answer.message == "") {
39+
console.log(chalk.bgRed("⛔️ Message can't be empty"));
40+
return;
41+
} else if (!answer.message.includes(" ")) {
42+
console.log(chalk.bgRed("⛔️ Message is too short"));
43+
return;
44+
}
45+
console.log("About to do exec");
46+
exec("git diff --cached --name-only", (err, stdout, stderr) => {
47+
if (err) {
48+
console.log("\n\n");
49+
console.log(
50+
chalk.bgRed("⛔️ Whops! Something went wrong. Try again!")
51+
);
52+
console.log(err);
53+
return;
54+
}
55+
if (stderr) {
56+
console.log(stderr);
57+
return;
58+
}
59+
60+
if (stdout.length <= 0) {
61+
console.log(chalk.bgRed("⛔️ Whops! No files available to commit."));
62+
console.log(
63+
"💡 Make sure to use " +
64+
chalk.bgWhite("git add") +
65+
" before trying to commit."
66+
);
67+
}
68+
});
69+
3870
exec(`git commit -m "${message}"`, (err, stdout, stderr) => {
3971
if (err) {
4072
console.log("Something went wrong. Try again!");

0 commit comments

Comments
 (0)