From 24febb3c906dd84f8ee19bae74509e42db034380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20J=C3=A4ppinen?= Date: Tue, 21 Jan 2020 16:41:55 +0200 Subject: [PATCH] fix: only warn about git add when it's the exact command This means that "custom" git add commands won't trigger the warning --- lib/runAll.js | 2 +- test/runAll.unmocked.spec.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/runAll.js b/lib/runAll.js index 10ce9a26e..ec0ed40bc 100644 --- a/lib/runAll.js +++ b/lib/runAll.js @@ -85,7 +85,7 @@ module.exports = async function runAll( shell }) - if (subTasks.some(subTask => subTask.command.includes('git add'))) { + if (subTasks.some(subTask => subTask.command === 'git add')) { hasDeprecatedGitAdd = true } diff --git a/test/runAll.unmocked.spec.js b/test/runAll.unmocked.spec.js index ea197ff9e..302afad8d 100644 --- a/test/runAll.unmocked.spec.js +++ b/test/runAll.unmocked.spec.js @@ -381,8 +381,6 @@ describe('runAll', () => { ).rejects.toThrowError() expect(console.printHistory()).toMatchInlineSnapshot(` " - WARN ‼ Some of your tasks use \`git add\` command. Please remove it from the config since all modifications made by tasks will be automatically added to the git commit index. - ERROR × lint-staged failed due to a git error. Any lost modifications can be restored from a git stash: @@ -693,12 +691,15 @@ describe('runAll', () => { // Run lint-staged with prettier --write to automatically fix the file // Since prettier reverts all changes, the commit should fail + // use the old syntax with manual `git add` to provide a warning message await expect( - gitCommit({ config: { '*.js': 'prettier --write' } }) + gitCommit({ config: { '*.js': ['prettier --write', 'git add'] } }) ).rejects.toThrowErrorMatchingInlineSnapshot(`"Something went wrong"`) expect(console.printHistory()).toMatchInlineSnapshot(` " + WARN ‼ Some of your tasks use \`git add\` command. Please remove it from the config since all modifications made by tasks will be automatically added to the git commit index. + WARN ‼ lint-staged prevented an empty git commit. Use the --allow-empty option to continue, or check your task configuration