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

Use index-based stash references #1270

Merged
merged 1 commit into from Mar 8, 2023
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
11 changes: 1 addition & 10 deletions lib/gitWorkflow.js
Expand Up @@ -104,16 +104,7 @@ export class GitWorkflow {
throw new Error('lint-staged automatic backup is missing!')
}

/**
* https://github.com/okonet/lint-staged/issues/1121
* Detect MSYS in login shell mode and escape braces
* to prevent interpolation
*/
if (!!process.env.MSYSTEM && !!process.env.LOGINSHELL) {
return `refs/stash@\\{${index}\\}`
}

return `refs/stash@{${index}}`
return String(index)
}

/**
Expand Down
42 changes: 1 addition & 41 deletions test/unit/getBackupStash.spec.js
Expand Up @@ -47,47 +47,7 @@ describe('gitWorkflow', () => {
].join('\n')
)

await expect(gitWorkflow.getBackupStash(ctx)).resolves.toEqual('refs/stash@{1}')
})

it('should return unescaped ref to the backup stash when using MSYS2 without login shell', 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
})

it('should return escaped ref to the backup stash when using MSYS2 with login shell', async () => {
const gitWorkflow = new GitWorkflow(options)
const ctx = getInitialState()

process.env.MSYSTEM = 'MSYS'
process.env.LOGINSHELL = 'bash'

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
delete process.env.LOGINSHELL
await expect(gitWorkflow.getBackupStash(ctx)).resolves.toEqual('1')
})
})
})