diff --git a/lib/gitWorkflow.js b/lib/gitWorkflow.js index f04901008..62a01e162 100644 --- a/lib/gitWorkflow.js +++ b/lib/gitWorkflow.js @@ -100,7 +100,7 @@ class GitWorkflow { ctx.errors.add(GetBackupStashError) throw new Error('lint-staged automatic backup is missing!') } - return `stash@{${index}}` + return `refs/stash@{${index}}` } /** diff --git a/test/integration.test.js b/test/integration.test.js index 33f4f0681..6be62a918 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -1032,6 +1032,27 @@ describe('lint-staged', () => { expect(await execGit(['rev-list', '--count', 'HEAD'])).toEqual('2') expect(await readFile('--looks-like-flag.js')).toEqual(testJsFilePretty) }) + + it('should work when a branch named stash exists', async () => { + // create a new branch called stash + await execGit(['branch', 'stash']) + + // Stage multiple ugly files + await appendFile('test.js', testJsFileUgly) + await execGit(['add', 'test.js']) + + await appendFile('test2.js', testJsFileUgly) + await execGit(['add', 'test2.js']) + + // Run lint-staged with `prettier --write` and commit pretty file + await gitCommit(fixJsConfig) + + // Nothing is wrong, so a new commit is created and file is pretty + expect(await execGit(['rev-list', '--count', 'HEAD'])).toEqual('2') + expect(await execGit(['log', '-1', '--pretty=%B'])).toMatch('test') + expect(await readFile('test.js')).toEqual(testJsFilePretty) + expect(await readFile('test2.js')).toEqual(testJsFilePretty) + }) }) describe('lintStaged', () => {