From 60fcd99451b88336a05ebbe71cda8909d2733ad7 Mon Sep 17 00:00:00 2001 From: Marcell Toth Date: Wed, 8 Mar 2023 16:55:15 +0100 Subject: [PATCH] fix: use index-based stash references for improved MSYS2 compatibility (#1270) --- lib/gitWorkflow.js | 11 +-------- test/unit/getBackupStash.spec.js | 42 +------------------------------- 2 files changed, 2 insertions(+), 51 deletions(-) diff --git a/lib/gitWorkflow.js b/lib/gitWorkflow.js index 9f0df245d..88c35139c 100644 --- a/lib/gitWorkflow.js +++ b/lib/gitWorkflow.js @@ -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) } /** diff --git a/test/unit/getBackupStash.spec.js b/test/unit/getBackupStash.spec.js index 4c55fab38..4b53819c1 100644 --- a/test/unit/getBackupStash.spec.js +++ b/test/unit/getBackupStash.spec.js @@ -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') }) }) })