From 51c5ac80da475f2255e12547018a3366ef6bd5a4 Mon Sep 17 00:00:00 2001 From: Philip Bjorge Date: Tue, 25 Aug 2020 08:42:53 -0700 Subject: [PATCH] fix: disambiguate stash reference (#906) * Disambiguate stash reference * Test verifying functionality with branch named stash * Revert fix to see if this is a real failure * Disable the test too * Add back tests Co-authored-by: Philip Bjorge --- lib/gitWorkflow.js | 2 +- test/integration.test.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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', () => {