lint-staged 17.0.6 → 17.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -772,6 +772,23 @@ module.exports = {
772
772
 
773
773
  ## Frequently Asked Questions
774
774
 
775
+ ### How does `lint-staged`'s stashing work?
776
+
777
+ <details>
778
+ <summary>Click to expand</summary>
779
+
780
+ When running `lint-staged` with the default configuration, the following happens:
781
+
782
+ 1. The entire original state is backed up in a git stash using `git stash create` and `git stash store`. This leaves all files in the worktree by default — the regular `git stash` command would also remove them. This most probably ignores any untracked files, which is the default behavior of `git stash`.
783
+ 1. If some file is "_partially staged_", meaning there's both staged and unstaged changes in the same file, lint-staged will additionally save all of these in a patch file, basically like `git diff --patch >> .git/lint-staged_unstaged.patch`. After this, the unstaged changes to these files are removed from the worktree so that tasks only see the staged changes
784
+ 1. After running tasks, any new modifications to the originally staged files are added to the index
785
+ 1. After this, any originally unstaged changes to "_partially staged_" files are restored by applying the patch file from step 2.
786
+ 1. In case of any errors, the state is reset with `git reset` and the original state restored from the git stash created in step 1.
787
+
788
+ If the process is interrupted at any point, it should be possible to restore changes from the git stash created in step 1. because it's only dropped in the last step, after successfully completing all previous steps in the process.
789
+
790
+ </details>
791
+
775
792
  ### The output of commit hook looks weird (no colors, duplicate lines, verbose output on Windows, …)
776
793
 
777
794
  <details>
package/lib/execGit.js CHANGED
@@ -4,9 +4,6 @@ import { createDebug } from './debug.js'
4
4
 
5
5
  const debugLog = createDebug('lint-staged:execGit')
6
6
 
7
- /** @example "warning: in the working copy of 'README.md', LF will be replaced by CRLF the next time Git touches it" */
8
- const GIT_CRLF_WARNING = /^warning.*CRLF.*the next time Git touches it/i
9
-
10
7
  /**
11
8
  * Explicitly never recurse commands into submodules, overriding local/global configuration.
12
9
  * @see https://git-scm.com/docs/git-config#Documentation/git-config.txt-submodulerecurse
@@ -19,27 +16,16 @@ export const GIT_GLOBAL_OPTIONS = [...NO_SUBMODULE_RECURSE]
19
16
  /** @type {(cmd: string[], options?: { cwd?: string }) => Promise<string>} */
20
17
  export const execGit = async (cmd, options) => {
21
18
  debugLog('Running git command:', cmd)
22
- const result = exec('git', [...NO_SUBMODULE_RECURSE, ...cmd], {
19
+ const result = await exec('git', [...NO_SUBMODULE_RECURSE, ...cmd], {
23
20
  nodeOptions: {
24
21
  env: options?.env,
25
22
  cwd: options?.cwd,
26
23
  },
27
24
  })
28
25
 
29
- let output = ''
30
- for await (const line of result) {
31
- if (GIT_CRLF_WARNING.test(line)) {
32
- debugLog('Stripped Git CRLF warning: %s', line)
33
- continue
34
- }
35
-
36
- output += line + '\n'
37
- }
38
- output = output.trimEnd()
39
-
40
26
  if (result.exitCode > 0) {
41
- throw new Error(output, { cause: result })
27
+ throw new Error(result.stderr.trimEnd(), { cause: result })
42
28
  }
43
29
 
44
- return output
30
+ return result.stdout.trimEnd()
45
31
  }
@@ -249,6 +249,8 @@ export class GitWorkflow {
249
249
 
250
250
  /** The stash line starts with the short hash, so we split from space and choose the first part */
251
251
  ctx.backupHash = stashes.find((line) => line.includes(STASH))?.split(' ')[0]
252
+
253
+ await this.restoreMergeStatus(ctx)
252
254
  } else {
253
255
  /** Save stash of all changes, keeping all files as-is */
254
256
  const stashHash = await this.execGit(['stash', 'create'])
@@ -440,7 +442,6 @@ export class GitWorkflow {
440
442
  await this.execGit(['reset', '--hard', 'HEAD'])
441
443
  await this.execGit(['stash', 'apply', '--quiet', '--index', await this.getBackupStash(ctx)])
442
444
 
443
- // Restore meta information about ongoing git merge
444
445
  await this.restoreMergeStatus(ctx)
445
446
 
446
447
  // Clean out patch
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lint-staged",
3
- "version": "17.0.6",
3
+ "version": "17.0.8",
4
4
  "description": "Lint files staged by git",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -55,7 +55,7 @@
55
55
  "listr2": "^10.2.1",
56
56
  "picomatch": "^4.0.4",
57
57
  "string-argv": "^0.3.2",
58
- "tinyexec": "1.2.2"
58
+ "tinyexec": "^1.2.4"
59
59
  },
60
60
  "optionalDependencies": {
61
61
  "yaml": "^2.9.0"
@@ -66,20 +66,20 @@
66
66
  "@commitlint/cli": "21.0.2",
67
67
  "@commitlint/config-conventional": "21.0.2",
68
68
  "@eslint/js": "10.0.1",
69
- "@vitest/coverage-istanbul": "4.1.7",
70
- "@vitest/eslint-plugin": "1.6.18",
69
+ "@vitest/coverage-istanbul": "4.1.9",
70
+ "@vitest/eslint-plugin": "1.6.20",
71
71
  "consolemock": "1.1.0",
72
72
  "cross-env": "10.1.0",
73
- "eslint": "10.4.1",
73
+ "eslint": "10.5.0",
74
74
  "eslint-config-prettier": "10.1.8",
75
- "eslint-plugin-n": "18.0.1",
75
+ "eslint-plugin-n": "18.1.0",
76
76
  "eslint-plugin-prettier": "5.5.6",
77
77
  "eslint-plugin-simple-import-sort": "13.0.0",
78
78
  "husky": "9.1.7",
79
79
  "mock-stdin": "1.0.0",
80
- "prettier": "3.8.3",
81
- "semver": "7.8.1",
82
- "vitest": "4.1.7"
80
+ "prettier": "3.8.4",
81
+ "semver": "7.8.4",
82
+ "vitest": "4.1.9"
83
83
  },
84
84
  "keywords": [
85
85
  "lint",