GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: do not drop backup stash when errors and `--fail-on-changes` was… · lint-staged/lint-staged@53bb27b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • gitWorkflow.js
    • index.js
    • state.js
    • symbols.js
  • test/integration
    • fail-on-changes.test.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/gitWorkflow.js‎

Copy file name to clipboardExpand all lines: lib/gitWorkflow.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { getDiffCommand } from './getDiffCommand.js'
99
import { parseGitZOutput } from './parseGitZOutput.js'
1010
import {
1111
ApplyEmptyCommitError,
12-
ExitCodeError,
12+
FailOnChangesError,
1313
GetBackupStashError,
1414
GitError,
1515
HideUnstagedChangesError,
@@ -317,7 +317,7 @@ export class GitWorkflow {
317317
const diffSha256 = calculateSha256(diff)
318318
debugLog('SHA-256 hash of changes after tasks is %S', this.diffSha256)
319319
if (this.unstagedDiffSha256 !== diffSha256) {
320-
ctx.errors.add(ExitCodeError)
320+
ctx.errors.add(FailOnChangesError)
321321
throw new Error('Tasks modified files and --fail-on-changes was used!')
322322
}
323323
}
Collapse file

‎lib/index.js‎

Copy file name to clipboardExpand all lines: lib/index.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { cleanupSkipped } from './state.js'
1515
import {
1616
ApplyEmptyCommitError,
1717
ConfigNotFoundError,
18-
ExitCodeError,
18+
FailOnChangesError,
1919
GetBackupStashError,
2020
GitError,
2121
RestoreUnstagedChangesError,
@@ -155,7 +155,7 @@ const lintStaged = async (
155155
logger.error(NO_CONFIGURATION)
156156
} else if (ctx.errors.has(ApplyEmptyCommitError)) {
157157
logger.warn(PREVENTED_EMPTY_COMMIT)
158-
} else if (ctx.errors.has(ExitCodeError)) {
158+
} else if (ctx.errors.has(FailOnChangesError)) {
159159
logger.warn(PREVENTED_TASK_MODIFICATIONS)
160160
} else if (ctx.errors.has(RestoreUnstagedChangesError)) {
161161
logger.warn(UNSTAGED_CHANGES_BACKUP_STASH_LOCATION)
Collapse file

‎lib/state.js‎

Copy file name to clipboardExpand all lines: lib/state.js
+9-7Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import EventEmitter from 'events'
22

33
import { GIT_ERROR, TASK_ERROR } from './messages.js'
44
import {
5-
ExitCodeError,
5+
FailOnChangesError,
66
GitError,
77
RestoreOriginalStateError,
88
RestoreUnstagedChangesError,
@@ -18,6 +18,7 @@ export const getInitialState = ({
1818
backupHash: null,
1919
errors: new Set([]),
2020
events: new EventEmitter(),
21+
shouldFailOnChanges: null,
2122
hasFilesToHide: null,
2223
output: [],
2324
quiet,
@@ -62,24 +63,25 @@ export const restoreUnstagedChangesSkipped = (ctx) => {
6263
export const restoreOriginalStateEnabled = (ctx) =>
6364
!!ctx.shouldRevert &&
6465
!!ctx.shouldBackup &&
65-
(ctx.errors.has(ExitCodeError) ||
66+
(ctx.errors.has(FailOnChangesError) ||
6667
ctx.errors.has(TaskError) ||
6768
ctx.errors.has(RestoreUnstagedChangesError))
6869

6970
export const restoreOriginalStateSkipped = (ctx) => {
7071
// Should be skipped in case of unknown git errors
71-
if (
72-
ctx.errors.has(GitError) &&
73-
!ctx.errors.has(RestoreUnstagedChangesError) &&
74-
!ctx.errors.has(ExitCodeError)
75-
) {
72+
if (ctx.errors.has(GitError) && !ctx.errors.has(RestoreUnstagedChangesError)) {
7673
return GIT_ERROR
7774
}
7875
}
7976

8077
export const cleanupEnabled = (ctx) => ctx.shouldBackup
8178

8279
export const cleanupSkipped = (ctx) => {
80+
// "--fail-on-changes" was used, so we shouldn't drop the backup stash
81+
if (ctx.errors.has(FailOnChangesError) && !ctx.shouldRevert) {
82+
return true
83+
}
84+
8385
// Should be skipped in case of unknown git errors
8486
if (restoreOriginalStateSkipped(ctx)) {
8587
return GIT_ERROR
Collapse file

‎lib/symbols.js‎

Copy file name to clipboardExpand all lines: lib/symbols.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ export const RestoreUnstagedChangesError = Symbol('RestoreUnstagedChangesError')
2626

2727
export const TaskError = Symbol('TaskError')
2828

29-
export const ExitCodeError = Symbol('ExitCodeError')
29+
export const FailOnChangesError = Symbol('FailOnChangesError')
Collapse file

‎test/integration/fail-on-changes.test.js‎

Copy file name to clipboardExpand all lines: test/integration/fail-on-changes.test.js
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('lint-staged', () => {
3030
)
3131

3232
test(
33-
'should not fail --fail-on-changes is used but tasks do not modify files',
33+
'should not fail when --fail-on-changes is used but tasks do not modify files',
3434
withGitIntegration(async ({ execGit, expect, gitCommit, readFile, writeFile }) => {
3535
await writeFile('.lintstagedrc.json', JSON.stringify(configFixtures.prettierWrite))
3636

@@ -66,7 +66,6 @@ describe('lint-staged', () => {
6666
lintStaged: {
6767
failOnChanges: true,
6868
revert: true,
69-
quiet: true,
7069
},
7170
})
7271
).rejects.toThrow('lint-staged failed because `--fail-on-changes` was used')

0 commit comments

Comments
0 (0)
You are visitor 01402605 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.