Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make exit 0 possible when commits required but missing #984

Merged
merged 3 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/release-it.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ const options = parseCliArguments([].slice.call(process.argv, 2));
updater({ pkg: pkg }).notify();
release(options).then(
() => process.exit(0),
() => process.exit(1)
({ code }) => process.exit(Number.isInteger(code) ? code : 1)
);
1 change: 1 addition & 0 deletions config/release-it.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"requireBranch": false,
"requireUpstream": true,
"requireCommits": false,
"requireCommitsFail": true,
"commitsPath": "",
"addUntrackedFiles": false,
"commit": true,
Expand Down
2 changes: 1 addition & 1 deletion lib/plugin/git/Git.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Git extends GitBase {
throw e(`No upstream configured for current branch.${EOL}Please set an upstream branch.`, docs);
}
if (this.options.requireCommits && (await this.getCommitsSinceLatestTag(this.options.commitsPath)) === 0) {
throw e(`There are no commits since the latest tag.`, docs);
throw e(`There are no commits since the latest tag.`, docs, this.options.requireCommitsFail);
}
}

Expand Down
6 changes: 5 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ const parseVersion = raw => {
};
};

const e = (message, docs) => new Error(docs ? `${message}${EOL}Documentation: ${docs}${EOL}` : message);
const e = (message, docs, fail = true) => {
const error = new Error(docs ? `${message}${EOL}Documentation: ${docs}${EOL}` : message);
error.code = fail ? 1 : 0;
return error;
};

export {
getSystemInfo,
Expand Down
13 changes: 13 additions & 0 deletions test/git.init.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ test.serial('should not throw if there are commits', async t => {
await t.notThrowsAsync(gitClient.init());
});

test.serial('should fail (exit code 1) if there are no commits', async t => {
const options = { git: { requireCommits: true } };
const gitClient = factory(Git, { options });
sh.exec('git tag 1.0.0');
await t.throwsAsync(gitClient.init(), { code: 1 });
});

test.serial('should not fail (exit code 0) if there are no commits', async t => {
const options = { git: { requireCommits: true, requireCommitsFail: false } };
const gitClient = factory(Git, { options });
sh.exec('git tag 1.0.0');
await t.throwsAsync(gitClient.init(), { code: 0 });

test.serial('should throw if there are no commits in specified path', async t => {
const options = { git: { requireCommits: true, commitsPath: 'dir' } };
const gitClient = factory(Git, { options });
Expand Down