lint-staged 13.0.1 → 13.0.2

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.
@@ -0,0 +1,18 @@
1
+ export function getDiffCommand(diff, diffFilter) {
2
+ /**
3
+ * Docs for --diff-filter option:
4
+ * @see https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203
5
+ */
6
+ const diffFilterArg = diffFilter !== undefined ? diffFilter.trim() : 'ACMR'
7
+
8
+ /** Use `--diff branch1...branch2` or `--diff="branch1 branch2", or fall back to default staged files */
9
+ const diffArgs = diff !== undefined ? diff.trim().split(' ') : ['--staged']
10
+
11
+ /**
12
+ * Docs for -z option:
13
+ * @see https://git-scm.com/docs/git-diff#Documentation/git-diff.txt--z
14
+ */
15
+ const diffCommand = ['diff', '--name-only', '-z', `--diff-filter=${diffFilterArg}`, ...diffArgs]
16
+
17
+ return diffCommand
18
+ }
@@ -3,27 +3,12 @@ import path from 'node:path'
3
3
  import normalize from 'normalize-path'
4
4
 
5
5
  import { execGit } from './execGit.js'
6
+ import { getDiffCommand } from './getDiffCommand.js'
6
7
  import { parseGitZOutput } from './parseGitZOutput.js'
7
8
 
8
9
  export const getStagedFiles = async ({ cwd = process.cwd(), diff, diffFilter } = {}) => {
9
10
  try {
10
- /**
11
- * Docs for --diff-filter option:
12
- * @see https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203
13
- */
14
- const diffFilterArg = diffFilter !== undefined ? diffFilter.trim() : 'ACMR'
15
-
16
- /** Use `--diff branch1...branch2` or `--diff="branch1 branch2", or fall back to default staged files */
17
- const diffArgs = diff !== undefined ? diff.trim().split(' ') : ['--staged']
18
-
19
- /**
20
- * Docs for -z option:
21
- * @see https://git-scm.com/docs/git-diff#Documentation/git-diff.txt--z
22
- */
23
- const lines = await execGit(
24
- ['diff', '--name-only', '-z', `--diff-filter=${diffFilterArg}`, ...diffArgs],
25
- { cwd }
26
- )
11
+ const lines = await execGit(getDiffCommand(diff, diffFilter), { cwd })
27
12
  if (!lines) return []
28
13
 
29
14
  return parseGitZOutput(lines).map((file) => normalize(path.resolve(cwd, file)))
@@ -4,6 +4,7 @@ import debug from 'debug'
4
4
 
5
5
  import { execGit } from './execGit.js'
6
6
  import { readFile, unlink, writeFile } from './file.js'
7
+ import { getDiffCommand } from './getDiffCommand.js'
7
8
  import {
8
9
  GitError,
9
10
  RestoreOriginalStateError,
@@ -65,12 +66,13 @@ const handleError = (error, ctx, symbol) => {
65
66
  }
66
67
 
67
68
  export class GitWorkflow {
68
- constructor({ allowEmpty, gitConfigDir, gitDir, matchedFileChunks }) {
69
+ constructor({ allowEmpty, gitConfigDir, gitDir, matchedFileChunks, diff, diffFilter }) {
69
70
  this.execGit = (args, options = {}) => execGit(args, { ...options, cwd: gitDir })
70
71
  this.deletedFiles = []
71
72
  this.gitConfigDir = gitConfigDir
72
73
  this.gitDir = gitDir
73
- this.unstagedDiff = null
74
+ this.diff = diff
75
+ this.diffFilter = diffFilter
74
76
  this.allowEmpty = allowEmpty
75
77
  this.matchedFileChunks = matchedFileChunks
76
78
 
@@ -262,7 +264,7 @@ export class GitWorkflow {
262
264
 
263
265
  debugLog('Done adding task modifications to index!')
264
266
 
265
- const stagedFilesAfterAdd = await this.execGit(['diff', '--name-only', '--cached'])
267
+ const stagedFilesAfterAdd = await this.execGit(getDiffCommand(this.diff, this.diffFilter))
266
268
  if (!stagedFilesAfterAdd && !this.allowEmpty) {
267
269
  // Tasks reverted all staged changes and the commit would be empty
268
270
  // Throw error to stop commit unless `--allow-empty` was used
package/lib/runAll.js CHANGED
@@ -262,7 +262,14 @@ export const runAll = async (
262
262
  relative: false,
263
263
  })
264
264
 
265
- const git = new GitWorkflow({ allowEmpty, gitConfigDir, gitDir, matchedFileChunks })
265
+ const git = new GitWorkflow({
266
+ allowEmpty,
267
+ gitConfigDir,
268
+ gitDir,
269
+ matchedFileChunks,
270
+ diff,
271
+ diffFilter,
272
+ })
266
273
 
267
274
  const runner = new Listr(
268
275
  [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lint-staged",
3
- "version": "13.0.1",
3
+ "version": "13.0.2",
4
4
  "description": "Lint files staged by git",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/okonet/lint-staged",