Navigation Menu

Skip to content

Commit

Permalink
fix: use index-based stash references for improved MSYS2 compatibility (
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelltoth committed Mar 8, 2023
1 parent 0d843ce commit 60fcd99
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 51 deletions.
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')
})
})
})

0 comments on commit 60fcd99

Please sign in to comment.