Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd4da24d

Browse files
committed
fix: skip backup stash when using the--diff option
1 parent1f06dd0 commitd4da24d

File tree

6 files changed

+44
-26
lines changed

6 files changed

+44
-26
lines changed

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ Options:
9292
-c, --config [path] path to configuration file, or - to read from stdin
9393
--cwd [path] run all tasks in specific directory, instead of the current
9494
-d, --debug print additional debug information (default: false)
95-
--diff [string] override the default "--staged" flag of "git diff" to get list of files
95+
--diff [string] override the default "--staged" flag of "git diff" to get list of files. Implies
96+
"--no-stash".
9697
--diff-filter [string] override the default "--diff-filter=ACMR" flag of "git diff" to get list of files
9798
--max-arg-length [number] maximum length of the command-line argument string (default: 0)
9899
--no-stash disable the backup stash, and do not revert in case of errors

‎bin/lint-staged.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ cli.option('-d, --debug', 'print additional debug information', false)
4444

4545
cli.option(
4646
'--diff [string]',
47-
'override the default "--staged" flag of "git diff" to get list of files'
47+
'override the default "--staged" flag of "git diff" to get list of files. Implies "--no-stash".'
4848
)
4949

5050
cli.option(

‎lib/index.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,25 @@ const lintStaged = async (
8686
debugLog('Unset GIT_LITERAL_PATHSPECS (was `%s`)',process.env.GIT_LITERAL_PATHSPECS)
8787
deleteprocess.env.GIT_LITERAL_PATHSPECS
8888

89+
constoptions={
90+
allowEmpty,
91+
concurrent,
92+
configObject,
93+
configPath,
94+
cwd,
95+
debug,
96+
diff,
97+
diffFilter,
98+
maxArgLength,
99+
quiet,
100+
relative,
101+
shell,
102+
stash,
103+
verbose,
104+
}
105+
89106
try{
90-
constctx=awaitrunAll(
91-
{
92-
allowEmpty,
93-
concurrent,
94-
configObject,
95-
configPath,
96-
cwd,
97-
debug,
98-
diff,
99-
diffFilter,
100-
maxArgLength,
101-
quiet,
102-
relative,
103-
shell,
104-
stash,
105-
verbose,
106-
},
107-
logger
108-
)
107+
constctx=awaitrunAll(options,logger)
109108
debugLog('Tasks were executed successfully!')
110109
printTaskOutput(ctx,logger)
111110
returntrue

‎lib/messages.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@ export const NO_STAGED_FILES = `${info} No staged files found.`
2828

2929
exportconstNO_TASKS=`${info} No staged files match any configured task.`
3030

31-
exportconstskippingBackup=(hasInitialCommit)=>{
32-
constreason=hasInitialCommit ?'`--no-stash` was used' :'there’s no initial commit yet'
31+
exportconstskippingBackup=(hasInitialCommit,diff)=>{
32+
constreason=
33+
diff!==undefined
34+
?'`--diff` was used'
35+
:hasInitialCommit
36+
?'`--no-stash` was used'
37+
:'there’s no initial commit yet'
38+
3339
returnyellow(`${warning} Skipping backup because${reason}.\n`)
3440
}
3541

‎lib/runAll.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,11 @@ export const runAll = async (
104104
.then(()=>true)
105105
.catch(()=>false)
106106

107-
// Lint-staged should create a backup stash only when there's an initial commit
108-
ctx.shouldBackup=hasInitialCommit&&stash
107+
// Lint-staged should create a backup stash only when there's an initial commit,
108+
// and when using the default list of staged files
109+
ctx.shouldBackup=hasInitialCommit&&stash&&diff===undefined
109110
if(!ctx.shouldBackup){
110-
logger.warn(skippingBackup(hasInitialCommit))
111+
logger.warn(skippingBackup(hasInitialCommit,diff))
111112
}
112113

113114
constfiles=awaitgetStagedFiles({cwd:gitDir, diff, diffFilter})

‎test/runAll.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ describe('runAll', () => {
4545

4646
beforeAll(()=>{
4747
console=makeConsoleMock()
48+
jest.clearAllMocks()
4849
})
4950

5051
afterEach(()=>{
@@ -372,4 +373,14 @@ describe('runAll', () => {
372373
expect(ctx.errors.has(ConfigNotFoundError)).toBe(true)
373374
}
374375
})
376+
377+
it('should warn when --no-stash was used',async()=>{
378+
awaitrunAll({configObject:{'*.js':['echo "sample"']},stash:false})
379+
expect(console.printHistory()).toMatch('Skipping backup because `--no-stash` was used')
380+
})
381+
382+
it('should warn when --diff was used',async()=>{
383+
awaitrunAll({configObject:{'*.js':['echo "sample"']},diff:'branch1...branch2'})
384+
expect(console.printHistory()).toMatch('Skipping backup because `--diff` was used')
385+
})
375386
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp