Skip to content

Commit 2f6182e

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

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

Diff for: @commitlint/cli/src/cli.js

+23-7
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,32 @@ 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 isHuskyParams =
233+
edit === '$HUSKY_GIT_PARAMS' || edit === '%HUSKY_GIT_PARAMS%';
234+
const isGitParams = edit === '$GIT_PARAMS' || edit === '%GIT_PARAMS%';
235+
236+
if (isHuskyParams || isGitParams) {
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 (isHuskyParams) {
241+
if (!('HUSKY_GIT_PARAMS' in process.env)) {
242+
throw new Error(
243+
`Received ${edit} as value for -e | --edit, but HUSKY_GIT_PARAMS is not available globally.`
244+
);
245+
}
246+
return process.env.HUSKY_GIT_PARAMS;
247+
}
248+
249+
if (isGitParams) {
250+
if (!('GIT_PARAMS' in process.env)) {
251+
throw new Error(
252+
`Received ${edit} as value for -e | --edit, but GIT_PARAMS is not available globally.`
253+
);
254+
}
255+
return process.env.GIT_PARAMS;
239256
}
240-
return process.env.HUSKY_GIT_PARAMS;
241257
}
242258
return edit;
243259
}

Diff for: @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)