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.
- package/lib/getDiffCommand.js +18 -0
- package/lib/getStagedFiles.js +2 -17
- package/lib/gitWorkflow.js +5 -3
- package/lib/runAll.js +8 -1
- package/package.json +1 -1
|
@@ -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
|
+
}
|
package/lib/getStagedFiles.js
CHANGED
|
@@ -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)))
|
package/lib/gitWorkflow.js
CHANGED
|
@@ -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.
|
|
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(
|
|
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({
|
|
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
|
[
|