Skip to content

Commit 2f15336

Browse files
authoredApr 5, 2020
fix: no longer include untracked files in backup stash (#827)
* 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. * fix: add --index flag to help text
1 parent 78a677a commit 2f15336

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed
 

Diff for: ‎lib/gitWorkflow.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ class GitWorkflow {
193193
// Manually check and backup if necessary
194194
await this.backupMergeStatus()
195195

196-
// Save stash of entire original state, including unstaged and untracked changes
197-
await this.execGit(['stash', 'save', '--include-untracked', STASH])
196+
// Save stash of original state
197+
await this.execGit(['stash', 'save', STASH])
198198
await this.execGit(['stash', 'apply', '--quiet', '--index', await this.getBackupStash()])
199199

200200
// Restore meta information about ongoing git merge, cleared by `git stash`

Diff for: ‎lib/runAll.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ const runAll = async (
254254
255255
> git stash list
256256
stash@{0}: On master: automatic lint-staged backup
257-
> git stash pop stash@{0}\n`)
257+
> git stash apply --index stash@{0}\n`)
258258
}
259259
}
260260

Diff for: ‎test/runAll.unmocked.2.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ describe('runAll', () => {
124124
125125
> git stash list
126126
stash@{0}: On master: automatic lint-staged backup
127-
> git stash pop stash@{0}
127+
> git stash apply --index stash@{0}
128128
"
129129
`)
130130
})

Diff for: ‎test/runAll.unmocked.spec.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ describe('runAll', () => {
428428
429429
> git stash list
430430
stash@{0}: On master: automatic lint-staged backup
431-
> git stash pop stash@{0}
431+
> git stash apply --index stash@{0}
432432
"
433433
`)
434434

@@ -608,6 +608,29 @@ describe('runAll', () => {
608608
expect(Buffer.from(await readFile('binary'), 'binary').toString()).toEqual('Hello, World!')
609609
})
610610

611+
it('should keep untracked files when taks fails', async () => {
612+
// Stage unfixable file
613+
await appendFile('test.js', testJsFileUnfixable)
614+
await execGit(['add', 'test.js'])
615+
616+
// Add untracked files
617+
await appendFile('test-untracked.js', testJsFilePretty)
618+
await appendFile('.gitattributes', 'binary\n')
619+
await writeFile('binary', Buffer.from('Hello, World!', 'binary'))
620+
621+
// Run lint-staged with `prettier --list-different` and commit pretty file
622+
await expect(
623+
gitCommit({ config: { '*.js': 'prettier --list-different' } })
624+
).rejects.toThrowError()
625+
626+
// Something was wrong so the repo is returned to original state
627+
expect(await execGit(['rev-list', '--count', 'HEAD'])).toEqual('1')
628+
expect(await execGit(['log', '-1', '--pretty=%B'])).toMatch('initial commit')
629+
expect(await readFile('test.js')).toEqual(testJsFileUnfixable)
630+
expect(await readFile('test-untracked.js')).toEqual(testJsFilePretty)
631+
expect(Buffer.from(await readFile('binary'), 'binary').toString()).toEqual('Hello, World!')
632+
})
633+
611634
it('should work when amending previous commit with unstaged changes', async () => {
612635
// Edit file from previous commit
613636
await appendFile('README.md', '\n## Amended\n')

0 commit comments

Comments
 (0)
Please sign in to comment.