Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add -- to git add command to denote pathspec starting #821

Merged
merged 1 commit into from Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/gitWorkflow.js
Expand Up @@ -238,7 +238,7 @@ class GitWorkflow {
await Promise.all(
// stagedFileChunks includes staged files that lint-staged originally detected.
// Add only these files so any 3rd-party edits to other files won't be included in the commit.
this.stagedFileChunks.map(stagedFiles => this.execGit(['add', ...stagedFiles]))
this.stagedFileChunks.map(stagedFiles => this.execGit(['add', '--', ...stagedFiles]))
)
debug('Done adding task modifications to index!')

Expand Down
8 changes: 8 additions & 0 deletions test/runAll.unmocked.spec.js
Expand Up @@ -1038,6 +1038,14 @@ describe('runAll', () => {
expect(await readFile('test.js')).toEqual(testJsFilePretty) // file was still fixed
expect(await readFile('test2.js')).toEqual(testJsFileUnfixable)
})

it('should handle files that begin with dash', async () => {
await appendFile('--looks-like-flag.js', testJsFileUgly)
await execGit(['add', '--', '--looks-like-flag.js'])
await expect(gitCommit(fixJsConfig)).resolves.toEqual(undefined)
expect(await execGit(['rev-list', '--count', 'HEAD'])).toEqual('2')
expect(await readFile('--looks-like-flag.js')).toEqual(testJsFilePretty)
})
})

describe('runAll', () => {
Expand Down