-
Notifications
You must be signed in to change notification settings - Fork 278
Add pre-commit.stash_unstaged_changes to control stashing
#1412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| --- | ||
| title: "stash_unstaged_changes" | ||
| --- | ||
|
|
||
| # `stash_unstaged_changes` | ||
|
|
||
| **Default: `true` for `pre-commit`** | ||
|
|
||
| Controls whether lefthook hides unstaged hunks from partially staged files before running the `pre-commit` hook. | ||
|
|
||
| When set to `false`, lefthook keeps the current on-disk contents of partially staged files visible during `pre-commit` execution. File selection does not change: `pre-commit` still uses the staged file set, and explicit templates like [`{staged_files}`](./run.md#staged_files) keep their usual meaning. | ||
|
|
||
| ::: callout info Note | ||
| Works only for the `pre-commit` hook. | ||
| ::: | ||
|
|
||
| ::: callout info Note | ||
| When this is `false`, [`stage_fixed`](./stage_fixed.md) is disabled for `pre-commit` jobs. | ||
| ::: | ||
|
|
||
| If you need to customize which files are passed to a job, use the hook-level [`files`](./files-global.md) option or job-level [`files`](./files.md) option. | ||
|
|
||
| #### Example | ||
|
|
||
| ```yml | ||
| # lefthook.yml | ||
|
|
||
| pre-commit: | ||
| stash_unstaged_changes: false | ||
| commands: | ||
| lint: | ||
| run: yarn eslint {staged_files} | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,13 +6,15 @@ const ChecksumFileName = "lefthook.checksum" | |
| // GhostHookName - the hook which logs are not shown and which is used for synchronizing hooks. | ||
| const GhostHookName = "prepare-commit-msg" | ||
|
|
||
| const PreCommitHookName = "pre-commit" | ||
|
|
||
| // AvailableHooks - list of hooks taken from https://git-scm.com/docs/githooks. | ||
| // Keep the order of the hooks same here for easy syncing. | ||
| var AvailableHooks = map[string]struct{}{ | ||
| "applypatch-msg": {}, | ||
| "pre-applypatch": {}, | ||
| "post-applypatch": {}, | ||
| "pre-commit": {}, | ||
| PreCommitHookName: {}, | ||
| "pre-merge-commit": {}, | ||
| "prepare-commit-msg": {}, | ||
| "commit-msg": {}, | ||
|
|
@@ -40,7 +42,7 @@ var AvailableHooks = map[string]struct{}{ | |
| } | ||
|
|
||
| func HookUsesStagedFiles(hook string) bool { | ||
| return hook == "pre-commit" | ||
| return hook == PreCommitHookName | ||
|
Comment on lines
9
to
+45
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please revert this change? I agree that this is a duplication, but it's more readable when using raw string values rather than constants
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do! |
||
| } | ||
|
|
||
| func HookUsesPushFiles(hook string) bool { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the naming: I would prefer some boolean that is
falseby default and you need to explicitly set ittrueto enable. That's the common approach for boolean values in lefthook configuration. Something likekeep_unstaged_filesorinclude_unstaged. But there's still a possible problem withstage_fixedconflict.