Skip to content

Commit 1f40e5a

Browse files
committed
✨ tweak: update commit.js to handle cases without changes.
1 parent 0a0d89b commit 1f40e5a

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

source/utils/commit.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,26 @@ async function askForCommitMessage() {
1010
output: process.stdout,
1111
});
1212

13-
rl.question(`Suggested commit message: ${prompt}\nDo you want to proceed? (y/n) `, (answer) => {
14-
if (answer.toLowerCase() === "y") {
15-
execa("git", ["commit", "-m", prompt])
16-
.then(() => {
17-
console.log("Changes committed successfully!");
18-
})
19-
.catch((error) => {
20-
console.error("Failed to commit changes:", error);
21-
});
22-
} else {
23-
console.log("Changes not committed.");
24-
}
13+
if (prompt) {
14+
rl.question(`Suggested commit message: ${prompt}\nDo you want to proceed? (y/n) `, (answer) => {
15+
if (answer.toLowerCase() === "y") {
16+
execa("git", ["commit", "-m", prompt])
17+
.then(() => {
18+
console.log("Changes committed successfully!");
19+
})
20+
.catch((error) => {
21+
console.error("Failed to commit changes:", error);
22+
});
23+
} else {
24+
console.log("Changes not committed.");
25+
}
2526

27+
rl.close();
28+
});
29+
} else {
30+
console.log("No changes to commit...");
2631
rl.close();
27-
});
32+
}
2833
}
2934

3035
export default askForCommitMessage;

0 commit comments

Comments
 (0)