Skip to content

Commit

Permalink
fix(cli): add old git params as alias to husky params
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric committed Nov 27, 2018
1 parent 126a712 commit d231b4a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
22 changes: 15 additions & 7 deletions @commitlint/cli/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,24 @@ function getEditValue(flags) {
// 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
// This has been superceded by the `-E HUSKY_GIT_PARAMS` / `-E HUSKY_GIT_PARAMS`
if (edit === '$HUSKY_GIT_PARAMS' || edit === '%HUSKY_GIT_PARAMS%') {
// This has been superceded by the `-E GIT_PARAMS` / `-E HUSKY_GIT_PARAMS`
const isGitParams = edit === '$GIT_PARAMS' || edit === '%GIT_PARAMS%';
const isHuskyParams =
edit === '$HUSKY_GIT_PARAMS' || edit === '%HUSKY_GIT_PARAMS%';

if (isGitParams || isHuskyParams) {
console.warn(`Using environment variable syntax (${edit}) in -e |\
--edit is deprecated. Use '{-E|--env} HUSKY_GIT_PARAMS instead'`);
if (!('HUSKY_GIT_PARAMS' in process.env)) {
throw new Error(
`Received ${edit} as value for -e | --edit, but HUSKY_GIT_PARAMS is not available globally.`
);

if (isGitParams && 'GIT_PARAMS' in process.env) {
return process.env.GIT_PARAMS;
}
if ('HUSKY_GIT_PARAMS' in process.env) {
return process.env.HUSKY_GIT_PARAMS;
}
return process.env.HUSKY_GIT_PARAMS;
throw new Error(
`Received ${edit} as value for -e | --edit, but GIT_PARAMS or HUSKY_GIT_PARAMS are not available globally.`
);
}
return edit;
}
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 @@ -109,6 +109,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 work with husky via commitlint -e $HUSKY_GIT_PARAMS', async () => {
const cwd = await git.bootstrap('fixtures/husky/integration');
await writePkg(
Expand Down

0 comments on commit d231b4a

Please sign in to comment.