Skip to content

Commit

Permalink
fix: no longer include untracked files in backup stash
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
iiroj committed Apr 5, 2020
1 parent 78a677a commit bda99ff
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/gitWorkflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
23 changes: 23 additions & 0 deletions test/runAll.unmocked.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit bda99ff

Please sign in to comment.