Skip to content

Commit

Permalink
fix: disambiguate stash reference (#906)
Browse files Browse the repository at this point in the history
* 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 <philip@philipbjorge.com>
  • Loading branch information
philipbjorge and Philip Bjorge committed Aug 25, 2020
1 parent 10b3218 commit 51c5ac8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/gitWorkflow.js
Expand Up @@ -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}}`
}

/**
Expand Down
21 changes: 21 additions & 0 deletions test/integration.test.js
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 51c5ac8

Please sign in to comment.