Repository: okonet/lint-staged
Pull request #1270 (2023-03-08 10:17:47)

Use index-based stash references
Following the discussion in #1267 I'm making this PR here to make the suggested change. Please see the issue for more details.

This also means we can remove the MSYS workaround, and the corresponding test.

iiroj: Thanks for the PR! I think a good commit message would be `fix: use index-based stash references for improved MSYS2 compatibility`, but I can reword it when merging.
codecov[bot]: # [Codecov](https://codecov.io/gh/okonet/lint-staged/pull/1270?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andrey+Okonetchnikov) Report
Patch coverage: **`100.00`**% and no project coverage change
> Comparison is base [(`0d843ce`)](https://codecov.io/gh/okonet/lint-staged/commit/0d843ce83060235635f1d1824c4bb744708b69ef?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andrey+Okonetchnikov) 100.00% compared to head [(`da82500`)](https://codecov.io/gh/okonet/lint-staged/pull/1270?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andrey+Okonetchnikov) 100.00%.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff            @@
##            master     #1270   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           26        26           
  Lines          735       733    -2     
  Branches       198       197    -1     
=========================================
- Hits           735       733    -2     
```


| [Impacted Files](https://codecov.io/gh/okonet/lint-staged/pull/1270?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andrey+Okonetchnikov) | Coverage Δ | |
|---|---|---|
| [lib/gitWorkflow.js](https://codecov.io/gh/okonet/lint-staged/pull/1270?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andrey+Okonetchnikov#diff-bGliL2dpdFdvcmtmbG93Lmpz) | `100.00% <100.00%> (ø)` | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andrey+Okonetchnikov). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andrey+Okonetchnikov)

</details>

[:umbrella: View full report at Codecov](https://codecov.io/gh/okonet/lint-staged/pull/1270?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andrey+Okonetchnikov).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andrey+Okonetchnikov).


Patch:
diff --git a/lib/gitWorkflow.js b/lib/gitWorkflow.js
index 9f0df24..88c3513 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)
   }
 
   /**


Test patch:
diff --git a/test/unit/getBackupStash.spec.js b/test/unit/getBackupStash.spec.js
index 4c55fab..4b53819 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')
     })
   })
 })