Skip to content

Commit

Permalink
fix: add -- to git add command to denote pathspec starting (#821)
Browse files Browse the repository at this point in the history
Without the -- denoter some paths might be interpreted as flags
  • Loading branch information
iiroj committed Mar 31, 2020
1 parent 8abb09f commit 226ccdb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
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

0 comments on commit 226ccdb

Please sign in to comment.