Skip to content

Commit 99390c3

Browse files
authoredFeb 7, 2023
fix: allow re-enabling --stash when using the --diff option
By default creating a backup stash is disabled when using `--diff`, because the typical use-case is to run _lint-staged_ in a CI environment with a clean working tree. It's now possible to re-enable this behavior by using the `--stash` option.
1 parent 421234c commit 99390c3

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed
 

‎README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ Options:
127127
- **`--debug`**: Run in debug mode. When set, it does the following:
128128
- uses [debug](https://github.com/visionmedia/debug) internally to log additional information about staged files, commands being executed, location of binaries, etc. Debug logs, which are automatically enabled by passing the flag, can also be enabled by setting the environment variable `$DEBUG` to `lint-staged*`.
129129
- uses [`verbose` renderer](https://github.com/SamVerschueren/listr-verbose-renderer) for `listr`; this causes serial, uncoloured output to the terminal, instead of the default (beautified, dynamic) output.
130-
- **`--diff`**: By default linters are filtered against all files staged in git, generated from `git diff --staged`. This option allows you to override the `--staged` flag with arbitrary revisions. For example to get a list of changed files between two branches, use `--diff="branch1...branch2"`. You can also read more from about [git diff](https://git-scm.com/docs/git-diff) and [gitrevisions](https://git-scm.com/docs/gitrevisions).
130+
- **`--diff`**: By default linters are filtered against all files staged in git, generated from `git diff --staged`. This option allows you to override the `--staged` flag with arbitrary revisions. For example to get a list of changed files between two branches, use `--diff="branch1...branch2"`. You can also read more from about [git diff](https://git-scm.com/docs/git-diff) and [gitrevisions](https://git-scm.com/docs/gitrevisions). This option also implies `--no-stash`.
131131
- **`--diff-filter`**: By default only files that are _added_, _copied_, _modified_, or _renamed_ are included. Use this flag to override the default `ACMR` value with something else: _added_ (`A`), _copied_ (`C`), _deleted_ (`D`), _modified_ (`M`), _renamed_ (`R`), _type changed_ (`T`), _unmerged_ (`U`), _unknown_ (`X`), or _pairing broken_ (`B`). See also the `git diff` docs for [--diff-filter](https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203).
132132
- **`--max-arg-length`**: long commands (a lot of files) are automatically split into multiple chunks when it detects the current shell cannot handle them. Use this flag to override the maximum length of the generated command string.
133-
- **`--no-stash`**: By default a backup stash will be created before running the tasks, and all task modifications will be reverted in case of an error. This option will disable creating the stash, and instead leave all modifications in the index when aborting the commit.
133+
- **`--no-stash`**: By default a backup stash will be created before running the tasks, and all task modifications will be reverted in case of an error. This option will disable creating the stash, and instead leave all modifications in the index when aborting the commit. Can be re-enabled with `--stash`
134134
- **`--quiet`**: Supress all CLI output, except from tasks.
135135
- **`--relative`**: Pass filepaths relative to `process.cwd()` (where `lint-staged` runs) to tasks. Default is `false`.
136136
- **`--shell`**: By default linter commands will be parsed for speed and security. This has the side-effect that regular shell scripts might not work as expected. You can skip parsing of commands with this option. To use a specific shell, use a path like `--shell "/bin/bash"`.

‎lib/runAll.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ export const runAll = async (
7777
quiet = false,
7878
relative = false,
7979
shell = false,
80-
stash = true,
80+
// Stashing should be disabled by default when the `diff` option is used
81+
stash = diff === undefined,
8182
verbose = false,
8283
},
8384
logger = console
@@ -104,9 +105,9 @@ export const runAll = async (
104105
.then(() => true)
105106
.catch(() => false)
106107

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
108+
// Lint-staged will create a backup stash only when there's an initial commit,
109+
// and when using the default list of staged files by default
110+
ctx.shouldBackup = hasInitialCommit && stash
110111
if (!ctx.shouldBackup) {
111112
logger.warn(skippingBackup(hasInitialCommit, diff))
112113
}

0 commit comments

Comments
 (0)
Please sign in to comment.