From 580eb4bed9e94ecfe20f18e20b4e6ffecbdb15af Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Tue, 27 Nov 2018 23:01:37 +0100 Subject: [PATCH] fix(cli): add old git params as alias to husky params --- @commitlint/cli/src/cli.js | 11 +++++++++-- @commitlint/cli/src/cli.test.js | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/@commitlint/cli/src/cli.js b/@commitlint/cli/src/cli.js index 4ca0739eef2..f152c9cad4e 100755 --- a/@commitlint/cli/src/cli.js +++ b/@commitlint/cli/src/cli.js @@ -228,8 +228,15 @@ 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` + if ( + [ + '$HUSKY_GIT_PARAMS', + '%HUSKY_GIT_PARAMS%', + '$GIT_PARAMS', + '%GIT_PARAMS%' + ].includes(edit) + ) { 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)) { diff --git a/@commitlint/cli/src/cli.test.js b/@commitlint/cli/src/cli.test.js index 34f1ebd72a6..2462ca56c00 100644 --- a/@commitlint/cli/src/cli.test.js +++ b/@commitlint/cli/src/cli.test.js @@ -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(