lint-staged 15.5.0 → 15.5.1
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 +3 -2
- package/lib/getStagedFiles.js +41 -11
- package/lib/gitWorkflow.js +6 -1
- package/package.json +12 -3
package/lib/getDiffCommand.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/** @type {(diff?: string, diffFilter?: string) => string[]} */
|
|
2
|
+
export const getDiffCommand = (diff, diffFilter) => {
|
|
2
3
|
/**
|
|
3
4
|
* Docs for --diff-filter option:
|
|
4
5
|
* @see https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203
|
|
@@ -12,7 +13,7 @@ export function getDiffCommand(diff, diffFilter) {
|
|
|
12
13
|
* Docs for -z option:
|
|
13
14
|
* @see https://git-scm.com/docs/git-diff#Documentation/git-diff.txt--z
|
|
14
15
|
*/
|
|
15
|
-
const diffCommand = ['diff',
|
|
16
|
+
const diffCommand = ['diff', `--diff-filter=${diffFilterArg}`, ...diffArgs]
|
|
16
17
|
|
|
17
18
|
return diffCommand
|
|
18
19
|
}
|
package/lib/getStagedFiles.js
CHANGED
|
@@ -5,21 +5,51 @@ import { getDiffCommand } from './getDiffCommand.js'
|
|
|
5
5
|
import { normalizePath } from './normalizePath.js'
|
|
6
6
|
import { parseGitZOutput } from './parseGitZOutput.js'
|
|
7
7
|
|
|
8
|
-
const listSubmoduleRoots = async ({ cwd }) => {
|
|
9
|
-
const lines = await execGit(['submodule', '--quiet', 'foreach', 'echo $displaypath'], { cwd })
|
|
10
|
-
return lines.split('\n').map((file) => normalizePath(path.resolve(cwd, file)))
|
|
11
|
-
}
|
|
12
|
-
|
|
13
8
|
export const getStagedFiles = async ({ cwd = process.cwd(), diff, diffFilter } = {}) => {
|
|
14
9
|
try {
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
/**
|
|
11
|
+
* With the raw output lines look like:
|
|
12
|
+
*
|
|
13
|
+
* :000000 100644 0000000 780ccd3\u0000A\u0000.gitmodules\u0000
|
|
14
|
+
* :000000 160000 0000000 1bb568e\u0000A\u0000submodule\u0000
|
|
15
|
+
*
|
|
16
|
+
* @see https://git-scm.com/docs/git-diff#_raw_output_format
|
|
17
|
+
*/
|
|
18
|
+
const output = await execGit([...getDiffCommand(diff, diffFilter), '--raw', '-z'], { cwd })
|
|
19
|
+
|
|
20
|
+
if (!output) return []
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Split from all colons and remove the first one, after which lines will look like:
|
|
24
|
+
*
|
|
25
|
+
* 000000 100644 0000000 780ccd3 A\u0000.gitmodules\u0000
|
|
26
|
+
* 000000 160000 0000000 47e5cff A\u0000submodule\u0000
|
|
27
|
+
*
|
|
28
|
+
* where '\u0000' is the NUL character from '-z' option. After that we
|
|
29
|
+
* parse the lines by splitting from NUL, and then split the first
|
|
30
|
+
* part from space. This yields us enough info both filter out submodule
|
|
31
|
+
* roots and get the filename.
|
|
32
|
+
*/
|
|
33
|
+
return output
|
|
34
|
+
.split(':')
|
|
35
|
+
.slice(1)
|
|
36
|
+
.map(parseGitZOutput)
|
|
37
|
+
.flatMap(([info, src, dst]) => {
|
|
38
|
+
const [, dstMode, , , ,] = info.split(' ')
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Filter out submodule root directory. "160000" is the object mode for submodules.
|
|
42
|
+
* @see https://github.com/git/git/blob/485f5f863615e670fd97ae40af744e14072cfe18/object.h#L114-L120
|
|
43
|
+
*/
|
|
44
|
+
if (dstMode === '160000') {
|
|
45
|
+
return []
|
|
46
|
+
}
|
|
17
47
|
|
|
18
|
-
|
|
48
|
+
/** "dst" exists when moving files, otherwise it's undefined and only "src" exists */
|
|
49
|
+
const filename = dst ?? src
|
|
19
50
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
.filter((file) => !submodules.includes(file))
|
|
51
|
+
return [normalizePath(path.resolve(cwd, filename))]
|
|
52
|
+
})
|
|
23
53
|
} catch {
|
|
24
54
|
return null
|
|
25
55
|
}
|
package/lib/gitWorkflow.js
CHANGED
|
@@ -278,7 +278,12 @@ export class GitWorkflow {
|
|
|
278
278
|
|
|
279
279
|
debugLog('Done adding task modifications to index!')
|
|
280
280
|
|
|
281
|
-
const stagedFilesAfterAdd = await this.execGit(
|
|
281
|
+
const stagedFilesAfterAdd = await this.execGit([
|
|
282
|
+
...getDiffCommand(this.diff, this.diffFilter),
|
|
283
|
+
'--name-only',
|
|
284
|
+
'-z',
|
|
285
|
+
])
|
|
286
|
+
|
|
282
287
|
if (!stagedFilesAfterAdd && !this.allowEmpty) {
|
|
283
288
|
// Tasks reverted all staged changes and the commit would be empty
|
|
284
289
|
// Throw error to stop commit unless `--allow-empty` was used
|
package/package.json
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lint-staged",
|
|
3
|
-
"version": "15.5.
|
|
3
|
+
"version": "15.5.1",
|
|
4
4
|
"description": "Lint files staged by git",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"repository":
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/lint-staged/lint-staged.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/lint-staged/lint-staged#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/lint-staged/lint-staged/issues"
|
|
13
|
+
},
|
|
7
14
|
"author": "Andrey Okonetchnikov <andrey@okonet.ru>",
|
|
8
15
|
"maintainers": [
|
|
9
16
|
"Lufty Wiranda <lufty.wiranda@gmail.com>",
|
|
@@ -17,7 +24,9 @@
|
|
|
17
24
|
"node": ">=18.12.0"
|
|
18
25
|
},
|
|
19
26
|
"type": "module",
|
|
20
|
-
"bin":
|
|
27
|
+
"bin": {
|
|
28
|
+
"lint-staged": "bin/lint-staged.js"
|
|
29
|
+
},
|
|
21
30
|
"exports": {
|
|
22
31
|
".": "./lib/index.js",
|
|
23
32
|
"./bin": "./bin/lint-staged.js",
|