diff --git a/test/gitStash.spec.js b/test/gitStash.spec.js index cddb9372d..7f879e26f 100644 --- a/test/gitStash.spec.js +++ b/test/gitStash.spec.js @@ -103,7 +103,7 @@ describe('git', () => { }) }) - describe('gitStashSave/gitStashPop', () => { + describe('saveStagedFiles/restoreStagedFiles', () => { it('should stash and restore WC state without a commit', async () => { expect(await gitStatus()).toMatchInlineSnapshot(` " M test.css @@ -118,11 +118,14 @@ M test.js" `) // Stashing files - await gitflow.gitStashSave(gitOpts) - expect(await gitStatus()).toMatchInlineSnapshot(`"M test.js"`) + await gitflow.saveStagedFiles(gitOpts) + expect(await gitStatus()).toMatchInlineSnapshot(` +" M test.css +M test.js" +`) // Restoring state - await gitflow.gitStashPop(gitOpts) + await gitflow.restoreStagedFiles(gitOpts) expect(await gitStatus()).toMatchInlineSnapshot(` " M test.css M test.js" @@ -139,11 +142,14 @@ D test.js" `) // Stashing files - await gitflow.gitStashSave(gitOpts) - expect(await gitStatus()).toMatchInlineSnapshot(`"D test.js"`) + await gitflow.saveStagedFiles(gitOpts) + expect(await gitStatus()).toMatchInlineSnapshot(` +" M test.css +D test.js" +`) // Restoring state - await gitflow.gitStashPop(gitOpts) + await gitflow.restoreStagedFiles(gitOpts) expect(await gitStatus()).toMatchInlineSnapshot(` " M test.css D test.js" @@ -160,11 +166,14 @@ D test.js" `) // Stashing files - await gitflow.gitStashSave(gitOpts) - expect(await gitStatus()).toMatchInlineSnapshot(`"R test.js -> test-renamed.js"`) + await gitflow.saveStagedFiles(gitOpts) + expect(await gitStatus()).toMatchInlineSnapshot(` +"R test.js -> test-renamed.js + M test.css" +`) // Restoring state - await gitflow.gitStashPop(gitOpts) + await gitflow.restoreStagedFiles(gitOpts) expect(await gitStatus()).toMatchInlineSnapshot(` "R test.js -> test-renamed.js M test.css" @@ -183,13 +192,18 @@ D test.js" `) // Stashing files - await gitflow.gitStashSave(gitOpts) - expect(await gitStatus()).toMatchInlineSnapshot(`"?? test-renamed.js"`) + await gitflow.saveStagedFiles(gitOpts) + expect(await gitStatus()).toMatchInlineSnapshot(` +" M test.css + D test.js +?? test-renamed.js" +`) // Restoring state - await gitflow.gitStashPop(gitOpts) + await gitflow.restoreStagedFiles(gitOpts) expect(await gitStatus()).toMatchInlineSnapshot(` " M test.css + D test.js ?? test-renamed.js" `) }) @@ -213,10 +227,8 @@ M test.js" expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(initialIndex) // Stashing state - await gitflow.gitStashSave(gitOpts) + await gitflow.saveStagedFiles(gitOpts) - // Only index should remain - expect(await gitStatus()).toMatchInlineSnapshot(`"M test.js"`) expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(initialIndex) // Do additional edits (imitate eslint --fix) @@ -229,12 +241,15 @@ M test.js" await fsp.writeFile(path.join(wcDirPath, 'test.js'), eslintContent) // Expect both indexed and modified state on one file - expect(await gitStatus()).toMatchInlineSnapshot(`"MM test.js"`) + expect(await gitStatus()).toMatchInlineSnapshot(` +" M test.css +MM test.js" +`) // and index isn't modified expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(initialIndex) // Restoring state - await gitflow.gitStashPop(gitOpts) + await gitflow.restoreStagedFiles(gitOpts) // Expect stashed files to be back expect(await gitStatus()).toMatchInlineSnapshot(` " M test.css @@ -272,10 +287,7 @@ MM test.js" expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(initialIndex) // Stashing state - await gitflow.gitStashSave(gitOpts) - - // Only index should remain - expect(await gitStatus()).toMatchInlineSnapshot(`"M test.js"`) + await gitflow.saveStagedFiles(gitOpts) // Do additional edits (imitate eslint --fix) await fsp.writeFile( @@ -285,13 +297,16 @@ MM test.js" };` ) - // Expect both indexed and modified state on one file - expect(await gitStatus()).toMatchInlineSnapshot(`"MM test.js"`) + // Expect both indexed and modified state + expect(await gitStatus()).toMatchInlineSnapshot(` +" M test.css +MM test.js" +`) // and index isn't modified expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(initialIndex) // Restoring state - await gitflow.gitStashPop(gitOpts) + await gitflow.restoreStagedFiles(gitOpts) // Expect stashed files to be back expect(await gitStatus()).toMatchInlineSnapshot(` @@ -321,10 +336,7 @@ M test.js" expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(initialIndex) // Stashing state - await gitflow.gitStashSave(gitOpts) - - // Only index should remain - expect(await gitStatus()).toMatchInlineSnapshot(`"M test.js"`) + await gitflow.saveStagedFiles(gitOpts) // Do additional edits (imitate eslint --fix) const newContent = `module.exports = { @@ -333,18 +345,16 @@ M test.js" await fsp.writeFile(path.join(wcDirPath, 'test.js'), newContent) // and add to index await gitflow.execGit(['add', 'test.js'], gitOpts) - await gitflow.updateStash(gitOpts) const newIndex = await gitflow.execGit(['diff', '--cached'], gitOpts) - // Expect only index changes - expect(await gitStatus()).toMatchInlineSnapshot(`"M test.js"`) + expect(await gitStatus()).toMatchInlineSnapshot(` +" M test.css +M test.js" +`) // and index is modified expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).not.toEqual(initialIndex) expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(newIndex) - // Restoring state - await gitflow.gitStashPop(gitOpts) - // Expect stashed files to be back expect(await gitStatus()).toMatchInlineSnapshot(` " M test.css @@ -382,10 +392,8 @@ MM test.js" expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(initialIndex) // Stashing state - await gitflow.gitStashSave(gitOpts) + await gitflow.saveStagedFiles(gitOpts) - // Only index should remain - expect(await gitStatus()).toMatchInlineSnapshot(`"M test.js"`) expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(initialIndex) // Do additional edits (imitate eslint --fix) @@ -397,7 +405,6 @@ MM test.js" ) // and add to index await gitflow.execGit(['add', 'test.js'], gitOpts) - await gitflow.updateStash(gitOpts) const newIndex = await gitflow.execGit(['diff', '--cached'], gitOpts) // Expect index is modified @@ -405,17 +412,14 @@ MM test.js" expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(newIndex) // Restoring state - await gitflow.gitStashPop(gitOpts) + await gitflow.restoreStagedFiles(gitOpts) // Expect stashed files to be back expect(await gitStatus()).toMatchInlineSnapshot(` " M test.css MM test.js" `) - // and content is back to user modifications - expect(await readFile('test.js')).toEqual(userContent) - // Expect formatting changes in the index - expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(newIndex) + expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(initialIndex) }) it('should add hooks fixes to index and working copy on partially staged files', async () => { @@ -462,10 +466,8 @@ MM test.js" const initialIndex = await gitflow.execGit(['diff', '--cached'], gitOpts) // Stashing state - await gitflow.gitStashSave(gitOpts) + await gitflow.saveStagedFiles(gitOpts) - // Only index should remain - expect(await gitStatus()).toMatchInlineSnapshot(`"M test.js"`) expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(initialIndex) // Imitate running prettier on the version from the index @@ -483,11 +485,10 @@ MM test.js" };` ) await gitflow.execGit(['add', 'test.js'], gitOpts) - await gitflow.updateStash(gitOpts) const indexAfterEslint = await gitflow.execGit(['diff', '--cached'], gitOpts) // Restoring state - await gitflow.gitStashPop(gitOpts) + await gitflow.restoreStagedFiles(gitOpts) // Expect stashed files to be back expect(await gitStatus()).toMatchInlineSnapshot(`"MM test.js"`)