Skip to content

Commit d231b4a

Browse files
committed
fix(cli): add old git params as alias to husky params
1 parent 126a712 commit d231b4a

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

@commitlint/cli/src/cli.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,24 @@ function getEditValue(flags) {
228228
// This does not work properly with win32 systems, where env variable declarations
229229
// use a different syntax
230230
// See https://github.com/marionebl/commitlint/issues/103 for details
231-
// This has been superceded by the `-E HUSKY_GIT_PARAMS` / `-E HUSKY_GIT_PARAMS`
232-
if (edit === '$HUSKY_GIT_PARAMS' || edit === '%HUSKY_GIT_PARAMS%') {
231+
// This has been superceded by the `-E GIT_PARAMS` / `-E HUSKY_GIT_PARAMS`
232+
const isGitParams = edit === '$GIT_PARAMS' || edit === '%GIT_PARAMS%';
233+
const isHuskyParams =
234+
edit === '$HUSKY_GIT_PARAMS' || edit === '%HUSKY_GIT_PARAMS%';
235+
236+
if (isGitParams || isHuskyParams) {
233237
console.warn(`Using environment variable syntax (${edit}) in -e |\
234238
--edit is deprecated. Use '{-E|--env} HUSKY_GIT_PARAMS instead'`);
235-
if (!('HUSKY_GIT_PARAMS' in process.env)) {
236-
throw new Error(
237-
`Received ${edit} as value for -e | --edit, but HUSKY_GIT_PARAMS is not available globally.`
238-
);
239+
240+
if (isGitParams && 'GIT_PARAMS' in process.env) {
241+
return process.env.GIT_PARAMS;
242+
}
243+
if ('HUSKY_GIT_PARAMS' in process.env) {
244+
return process.env.HUSKY_GIT_PARAMS;
239245
}
240-
return process.env.HUSKY_GIT_PARAMS;
246+
throw new Error(
247+
`Received ${edit} as value for -e | --edit, but GIT_PARAMS or HUSKY_GIT_PARAMS are not available globally.`
248+
);
241249
}
242250
return edit;
243251
}

@commitlint/cli/src/cli.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,24 @@ test('should work with husky commitmsg hook in sub packages', async () => {
109109
await execa('git', ['commit', '-m', '"test: this should work"'], {cwd});
110110
});
111111

112+
test('should work with husky via commitlint -e $GIT_PARAMS', async () => {
113+
const cwd = await git.bootstrap('fixtures/husky/integration');
114+
await writePkg({scripts: {commitmsg: `'${bin}' -e $GIT_PARAMS`}}, {cwd});
115+
116+
await execa('npm', ['install'], {cwd});
117+
await execa('git', ['add', 'package.json'], {cwd});
118+
await execa('git', ['commit', '-m', '"test: this should work"'], {cwd});
119+
});
120+
121+
test('should work with husky via commitlint -e %GIT_PARAMS%', async () => {
122+
const cwd = await git.bootstrap('fixtures/husky/integration');
123+
await writePkg({scripts: {commitmsg: `'${bin}' -e %GIT_PARAMS%`}}, {cwd});
124+
125+
await execa('npm', ['install'], {cwd});
126+
await execa('git', ['add', 'package.json'], {cwd});
127+
await execa('git', ['commit', '-m', '"test: this should work"'], {cwd});
128+
});
129+
112130
test('should work with husky via commitlint -e $HUSKY_GIT_PARAMS', async () => {
113131
const cwd = await git.bootstrap('fixtures/husky/integration');
114132
await writePkg(

0 commit comments

Comments
 (0)