Skip to content

Commit

Permalink
fix: handle empty repository and no release tag
Browse files Browse the repository at this point in the history
  • Loading branch information
qoomon committed Aug 17, 2022
1 parent b8d8a18 commit 940f809
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions lib/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function getLastTag(
.then(output => output.trim())
.catch(err => {
// return undefined if no tag was found
if (err.exitCode === 128) {
if (err.code === 128) {
return;
}
throw err;
Expand All @@ -31,7 +31,14 @@ const LOG_FIELD_SEPARATOR = '===LOG_FIELD_SEPARATOR===';
async function getCommitLog(from, to = 'HEAD') {
const gitLogFormat = ["%h", "%aI", "%s", "%b"].join(LOG_FIELD_SEPARATOR) + LOG_COMMIT_DELIMITER;
const gitLog = await execAsync(`git log --reverse --format=${gitLogFormat} ${from ? `${from}..` : ''}${to}`, {encoding: 'UTF-8'})
.then(result => result.split(LOG_COMMIT_DELIMITER + '\n').slice(0, -1));
.then(result => result.split(LOG_COMMIT_DELIMITER + '\n').slice(0, -1))
.catch(err => {
// return empty log if no commits available
if (err.code === 128) {
return [];
}
throw err;
});

return gitLog.map(commit => commit.split(LOG_FIELD_SEPARATOR))
.map(fields => ({
Expand Down
2 changes: 1 addition & 1 deletion lib/gitCommitConvention.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = function (convention, commitAnchor = 'HEAD') {
this.getVersion = async function () {
let version = {
major: 0,
minor: 0,
minor: 1,
patch: 0
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "git-conventional-commits",
"version": "2.1.0",
"version": "2.1.1",
"description": "git conventional commits util",
"licence": "GPLv3",
"main": "cli.js",
Expand Down

0 comments on commit 940f809

Please sign in to comment.