-
-
Notifications
You must be signed in to change notification settings - Fork 425
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: correctly handle git stash when using MSYS2 #1178
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1178 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 26 26
Lines 733 735 +2
Branches 197 198 +1
=========================================
+ Hits 733 735 +2
Continue to review full report at Codecov.
|
Thank you for the PR! Please rename the commit as something like Also, this needs at least an unit test, let me figure out how to do it. |
Something like this will properly test the import { execGit } from '../../lib/execGit.js'
import { GitWorkflow, STASH } from '../../lib/gitWorkflow.js'
import { getInitialState } from '../../lib/state.js'
import { GetBackupStashError } from '../../lib/symbols'
jest.mock('../../lib/execGit.js', () => ({
execGit: jest.fn(async () => ''),
}))
describe('gitWorkflow', () => {
const options = { gitConfigDir: '.' }
describe('getBackupStash', () => {
it('should throw when stash not found', async () => {
const gitWorkflow = new GitWorkflow(options)
const ctx = getInitialState()
await expect(gitWorkflow.getBackupStash(ctx)).rejects.toThrowError(
'lint-staged automatic backup is missing!'
)
expect(ctx.errors.has(GetBackupStashError)).toEqual(true)
})
it('should throw when stash not found even when other stashes are', async () => {
const gitWorkflow = new GitWorkflow(options)
const ctx = getInitialState()
execGit.mockResolvedValueOnce('stash@{0}: some random stuff')
await expect(gitWorkflow.getBackupStash(ctx)).rejects.toThrowError(
'lint-staged automatic backup is missing!'
)
expect(ctx.errors.has(GetBackupStashError)).toEqual(true)
})
it('should return ref to the backup stash', async () => {
const gitWorkflow = new GitWorkflow(options)
const ctx = getInitialState()
execGit.mockResolvedValueOnce(
[
'stash@{0}: some random stuff',
`stash@{1}: ${STASH}`,
'stash@{2}: other random stuff',
].join('\n')
)
await expect(gitWorkflow.getBackupStash(ctx)).resolves.toEqual('refs/stash@{1}')
})
it('should return escaped ref to the backup stash when using MSYS2', async () => {
const gitWorkflow = new GitWorkflow(options)
const ctx = getInitialState()
process.env.MSYSTEM = 'MSYS'
execGit.mockResolvedValueOnce(
[
'stash@{0}: some random stuff',
`stash@{1}: ${STASH}`,
'stash@{2}: other random stuff',
].join('\n')
)
await expect(gitWorkflow.getBackupStash(ctx)).resolves.toEqual('refs/stash@\\{1\\}')
delete process.env.MSYSTEM
})
})
}) |
… aren't run on MSYS2 environment
🎉 This PR is included in version 13.0.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This simple patch fixes #1121 by detecting MSYS2 shell via env variables set by MSYS2 (https://github.com/msys2/MSYS2-packages/blob/master/filesystem/msys2_shell.cmd) and adds escaped braces if MSYS2 is found.