Skip to content

Commit

Permalink
fix: only warn about git add when it's the exact command
Browse files Browse the repository at this point in the history
This means that "custom" git add commands won't trigger the warning
  • Loading branch information
iiroj committed Jan 21, 2020
1 parent e646b2c commit 24febb3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/runAll.js
Expand Up @@ -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
}

Expand Down
7 changes: 4 additions & 3 deletions test/runAll.unmocked.spec.js
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 24febb3

Please sign in to comment.