From bda99ff67d823d1e264fe90be65bc81a1dcfecda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20Ja=CC=88ppinen?= Date: Fri, 3 Apr 2020 07:27:23 +0300 Subject: [PATCH 1/2] fix: no longer include untracked files in backup stash Since v10.1 having untracked files in the backup stash causes revert to fail, because the stash will not apply with the same files already on disk. --- lib/gitWorkflow.js | 4 ++-- test/runAll.unmocked.spec.js | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/gitWorkflow.js b/lib/gitWorkflow.js index 321b137b5..2d2822dcd 100644 --- a/lib/gitWorkflow.js +++ b/lib/gitWorkflow.js @@ -193,8 +193,8 @@ class GitWorkflow { // Manually check and backup if necessary await this.backupMergeStatus() - // Save stash of entire original state, including unstaged and untracked changes - await this.execGit(['stash', 'save', '--include-untracked', STASH]) + // Save stash of original state + await this.execGit(['stash', 'save', STASH]) await this.execGit(['stash', 'apply', '--quiet', '--index', await this.getBackupStash()]) // Restore meta information about ongoing git merge, cleared by `git stash` diff --git a/test/runAll.unmocked.spec.js b/test/runAll.unmocked.spec.js index 1f78eece1..922ca402d 100644 --- a/test/runAll.unmocked.spec.js +++ b/test/runAll.unmocked.spec.js @@ -608,6 +608,29 @@ describe('runAll', () => { expect(Buffer.from(await readFile('binary'), 'binary').toString()).toEqual('Hello, World!') }) + it('should keep untracked files when taks fails', async () => { + // Stage unfixable file + await appendFile('test.js', testJsFileUnfixable) + await execGit(['add', 'test.js']) + + // Add untracked files + await appendFile('test-untracked.js', testJsFilePretty) + await appendFile('.gitattributes', 'binary\n') + await writeFile('binary', Buffer.from('Hello, World!', 'binary')) + + // Run lint-staged with `prettier --list-different` and commit pretty file + await expect( + gitCommit({ config: { '*.js': 'prettier --list-different' } }) + ).rejects.toThrowError() + + // Something was wrong so the repo is returned to original state + expect(await execGit(['rev-list', '--count', 'HEAD'])).toEqual('1') + expect(await execGit(['log', '-1', '--pretty=%B'])).toMatch('initial commit') + expect(await readFile('test.js')).toEqual(testJsFileUnfixable) + expect(await readFile('test-untracked.js')).toEqual(testJsFilePretty) + expect(Buffer.from(await readFile('binary'), 'binary').toString()).toEqual('Hello, World!') + }) + it('should work when amending previous commit with unstaged changes', async () => { // Edit file from previous commit await appendFile('README.md', '\n## Amended\n') From 76cf26b44f3055fb5b7d5b1e0d51da9a1b5df515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20Ja=CC=88ppinen?= Date: Fri, 3 Apr 2020 08:52:45 +0300 Subject: [PATCH 2/2] fix: add --index flag to help text --- lib/runAll.js | 2 +- test/runAll.unmocked.2.spec.js | 2 +- test/runAll.unmocked.spec.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/runAll.js b/lib/runAll.js index 328efa5d9..ef6ca672d 100644 --- a/lib/runAll.js +++ b/lib/runAll.js @@ -254,7 +254,7 @@ const runAll = async ( > git stash list stash@{0}: On master: automatic lint-staged backup - > git stash pop stash@{0}\n`) + > git stash apply --index stash@{0}\n`) } } diff --git a/test/runAll.unmocked.2.spec.js b/test/runAll.unmocked.2.spec.js index 86aea6588..b20fb3477 100644 --- a/test/runAll.unmocked.2.spec.js +++ b/test/runAll.unmocked.2.spec.js @@ -124,7 +124,7 @@ describe('runAll', () => { > git stash list stash@{0}: On master: automatic lint-staged backup - > git stash pop stash@{0} + > git stash apply --index stash@{0} " `) }) diff --git a/test/runAll.unmocked.spec.js b/test/runAll.unmocked.spec.js index 922ca402d..3a7a82217 100644 --- a/test/runAll.unmocked.spec.js +++ b/test/runAll.unmocked.spec.js @@ -428,7 +428,7 @@ describe('runAll', () => { > git stash list stash@{0}: On master: automatic lint-staged backup - > git stash pop stash@{0} + > git stash apply --index stash@{0} " `)