Skip to content

Commit 24febb3

Browse files
committed
fix: only warn about git add when it's the exact command
This means that "custom" git add commands won't trigger the warning
1 parent e646b2c commit 24febb3

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

lib/runAll.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ module.exports = async function runAll(
8585
shell
8686
})
8787

88-
if (subTasks.some(subTask => subTask.command.includes('git add'))) {
88+
if (subTasks.some(subTask => subTask.command === 'git add')) {
8989
hasDeprecatedGitAdd = true
9090
}
9191

test/runAll.unmocked.spec.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,6 @@ describe('runAll', () => {
381381
).rejects.toThrowError()
382382
expect(console.printHistory()).toMatchInlineSnapshot(`
383383
"
384-
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.
385-
386384
ERROR
387385
× lint-staged failed due to a git error.
388386
Any lost modifications can be restored from a git stash:
@@ -693,12 +691,15 @@ describe('runAll', () => {
693691

694692
// Run lint-staged with prettier --write to automatically fix the file
695693
// Since prettier reverts all changes, the commit should fail
694+
// use the old syntax with manual `git add` to provide a warning message
696695
await expect(
697-
gitCommit({ config: { '*.js': 'prettier --write' } })
696+
gitCommit({ config: { '*.js': ['prettier --write', 'git add'] } })
698697
).rejects.toThrowErrorMatchingInlineSnapshot(`"Something went wrong"`)
699698

700699
expect(console.printHistory()).toMatchInlineSnapshot(`
701700
"
701+
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.
702+
702703
WARN
703704
‼ lint-staged prevented an empty git commit.
704705
Use the --allow-empty option to continue, or check your task configuration

0 commit comments

Comments
 (0)