Skip to content

fix(cli): add support for GIT_PARAMS on windows. Closes #103 #175

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

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions @commitlint/cli/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,29 @@ function checkFromHistory(flags) {
function normalizeFlags(flags) {
// The `edit` flag is either a boolean or a string but we are only allowed
// to specify one of them in minimist
if (flags.edit === '') {
return merge({}, flags, {edit: true, e: true});
}
const edit = flags.edit === '' ? true : normalizeEdit(flags.edit);
return merge({}, flags, {edit, e: edit});
}

return flags;
function normalizeEdit(edit) {
if (typeof edit === 'boolean') {
return edit;
}
// The recommended method to specify -e with husky is commitlint -e $GIT_PARAMS
// This does not work properly with win32 systems, where env variable declarations
// use a different syntax
// See https://github.com/marionebl/commitlint/issues/103 for details
if (edit === '$GIT_PARAMS' || edit === '%GIT_PARAMS%') {
if (!('GIT_PARAMS' in process.env)) {
throw new Error(
`Received ${
edit
} as value for -e | --edit, but GIT_PARAMS is not available globally.`
);
}
return process.env.GIT_PARAMS;
}
return edit;
}

function getSeed(seed) {
Expand Down
18 changes: 18 additions & 0 deletions @commitlint/cli/src/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@ test('should work with husky commitmsg hook in sub packages', async () => {
await execa('git', ['commit', '-m', '"test: this should work"'], {cwd});
});

test('should work with husky via commitlint -e $GIT_PARAMS', async () => {
const cwd = await git.bootstrap('fixtures/husky/integration');
await writePkg({scripts: {commitmsg: `${bin} -e $GIT_PARAMS`}}, {cwd});

await execa('npm', ['install'], {cwd});
await execa('git', ['add', 'package.json'], {cwd});
await execa('git', ['commit', '-m', '"test: this should work"'], {cwd});
});

test('should work with husky via commitlint -e %GIT_PARAMS%', async () => {
const cwd = await git.bootstrap('fixtures/husky/integration');
await writePkg({scripts: {commitmsg: `${bin} -e %GIT_PARAMS%`}}, {cwd});

await execa('npm', ['install'], {cwd});
await execa('git', ['add', 'package.json'], {cwd});
await execa('git', ['commit', '-m', '"test: this should work"'], {cwd});
});

test('should pick up parser preset and fail accordingly', async t => {
const cwd = await git.bootstrap('fixtures/parser-preset');
const actual = await cli(['--parser-preset', './parser-preset'], {cwd})(
Expand Down