Skip to content

Commit 60fcd99

Browse files
authored
fix: use index-based stash references for improved MSYS2 compatibility (#1270)
1 parent 0d843ce commit 60fcd99

File tree

2 files changed

+2
-51
lines changed

2 files changed

+2
-51
lines changed

lib/gitWorkflow.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,7 @@ export class GitWorkflow {
104104
throw new Error('lint-staged automatic backup is missing!')
105105
}
106106

107-
/**
108-
* https://github.com/okonet/lint-staged/issues/1121
109-
* Detect MSYS in login shell mode and escape braces
110-
* to prevent interpolation
111-
*/
112-
if (!!process.env.MSYSTEM && !!process.env.LOGINSHELL) {
113-
return `refs/stash@\\{${index}\\}`
114-
}
115-
116-
return `refs/stash@{${index}}`
107+
return String(index)
117108
}
118109

119110
/**

test/unit/getBackupStash.spec.js

+1-41
Original file line numberDiff line numberDiff line change
@@ -47,47 +47,7 @@ describe('gitWorkflow', () => {
4747
].join('\n')
4848
)
4949

50-
await expect(gitWorkflow.getBackupStash(ctx)).resolves.toEqual('refs/stash@{1}')
51-
})
52-
53-
it('should return unescaped ref to the backup stash when using MSYS2 without login shell', async () => {
54-
const gitWorkflow = new GitWorkflow(options)
55-
const ctx = getInitialState()
56-
57-
process.env.MSYSTEM = 'MSYS'
58-
59-
execGit.mockResolvedValueOnce(
60-
[
61-
'stash@{0}: some random stuff',
62-
`stash@{1}: ${STASH}`,
63-
'stash@{2}: other random stuff',
64-
].join('\n')
65-
)
66-
67-
await expect(gitWorkflow.getBackupStash(ctx)).resolves.toEqual('refs/stash@{1}')
68-
69-
delete process.env.MSYSTEM
70-
})
71-
72-
it('should return escaped ref to the backup stash when using MSYS2 with login shell', async () => {
73-
const gitWorkflow = new GitWorkflow(options)
74-
const ctx = getInitialState()
75-
76-
process.env.MSYSTEM = 'MSYS'
77-
process.env.LOGINSHELL = 'bash'
78-
79-
execGit.mockResolvedValueOnce(
80-
[
81-
'stash@{0}: some random stuff',
82-
`stash@{1}: ${STASH}`,
83-
'stash@{2}: other random stuff',
84-
].join('\n')
85-
)
86-
87-
await expect(gitWorkflow.getBackupStash(ctx)).resolves.toEqual('refs/stash@\\{1\\}')
88-
89-
delete process.env.MSYSTEM
90-
delete process.env.LOGINSHELL
50+
await expect(gitWorkflow.getBackupStash(ctx)).resolves.toEqual('1')
9151
})
9252
})
9353
})

0 commit comments

Comments
 (0)