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: disambiguate stash reference #906

Merged
merged 6 commits into from Aug 25, 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 @@ -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