Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: no longer include untracked files in backup stash #827

Merged
merged 2 commits into from Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/gitWorkflow.js
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
2 changes: 1 addition & 1 deletion lib/runAll.js
Expand Up @@ -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`)
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/runAll.unmocked.2.spec.js
Expand Up @@ -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}
"
`)
})
Expand Down
25 changes: 24 additions & 1 deletion test/runAll.unmocked.spec.js
Expand Up @@ -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}
"
`)

Expand Down 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