Conversation
90b1e2f to
372452d
Compare
docs/workspace.md
Outdated
| prek run lint --skip tests | ||
|
|
||
| # Run all hooks from 'src' and 'docs' but skip 'src/legacy' | ||
| prek run src docs --skip src/legacy |
There was a problem hiding this comment.
I think it would be nicer and less ambiguous if skipping path would have different flag:
--skip-path
There was a problem hiding this comment.
Similarly it feels a bit wrong to be able to pass both hook id and path as run argument. This might lead to a number of ambuiguties.
Maybe paths should be prefixed and have multiplication option or allow them to be colon separated:
prek run --path srcprek run --path src --path doc
or:
prek run --paths src:doc
|
Hey @potiuk! I was going through the details of the workspace document and was wondering if you could take another look at it. Here’s the link: https://github.com/j178/prek/pull/583/files#diff-1f5ae9e589a468b8b28636fef58e8221229fc93e403da49bf89dcf4940d2e4e1. Thanks! |
|
|
||
| ### Skipping Projects or Hooks | ||
|
|
||
| You can skip specific projects or hooks using the `--skip` option, with the same syntax as for selecting projects or hooks. |
There was a problem hiding this comment.
One thing missing here is describing how you skip multiple skips. It is not clear if it is the same as SKIP (coma separated)? or multiple --skip. Also it's not clear if SKIP env var also works with paths. If it does then theorethically , is not great idea as path separator :).
potiuk
left a comment
There was a problem hiding this comment.
Looks really cool. The only thing I think needs more clarity is how to handle multiple skips
|
Looks pretty good! |
…ode) (#481) * Remove color from trace log Since `tracing-subscriber 0.3.20`, ANSI codes will be escaped so that color can not be shown in log. tokio-rs/tracing@4c52ca5 * Refactor project constructure # Conflicts: # src/cli/run/run.rs * . # Conflicts: # src/workspace.rs # Conflicts: # src/workspace.rs # Conflicts: # src/workspace.rs . # Conflicts: # src/git.rs # Conflicts: # src/git.rs # Conflicts: # src/git.rs # src/languages/script.rs Support multiple `.pre-commit-connfig.yaml` in a workspace (monorepo mode) . . Make it compile Fix . . . Fix Fix Fix . . . # Conflicts: # src/builtin/pre_commit_hooks/fix_trailing_whitespace.rs # src/builtin/pre_commit_hooks/mod.rs # src/hook.rs # src/languages/docker.rs # src/languages/docker_image.rs # src/languages/golang/golang.rs # src/languages/node/node.rs # src/languages/python/python.rs # src/languages/system.rs # src/run.rs * Refactor * Fix * . * Fix `--config FILE` * Add docs * Misc * Fix # Conflicts: # README.md
* . * Fix config not staged relative filename display
…orkspace mode (#595) * Support `prek install|install-hooks|hook-impl|init-template-dir` in workspace mode * Fix * Fix windows # Conflicts: # src/cli/hook_impl.rs # tests/hook_impl.rs # Conflicts: # src/cli/install.rs
* Implement `auto-update` in workspace mode * Deduplicate remote hooks * Minor
* selection * . * complete * rewrite * Fix * Fix docs * Update doc * Fix single config mode * Improve * Fix doc * Fixes and tweaks * Fix tests * Fixes and tests * Use path clean instead of canonicalized
Closes #18
Workspace Mode
preksupports a powerful workspace mode that allows you to manage multiple projects with their own pre-commit configurations within a single repository. This is particularly useful for monorepos or projects with complex directory structures.Overview
A workspace is a directory structure that contains:
.pre-commit-config.yamlfile.pre-commit-config.yamlfiles in subdirectoriesEach directory containing a
.pre-commit-config.yamlfile is considered a project. Projects can be nested infinitely deep.Discovery
When you run
prek runwithout the--configoption,prekautomatically discovers the workspace:Find workspace root: Starting from the current working directory,
prekwalks up the directory tree until it finds a.pre-commit-config.yamlfile. This becomes the workspace root.Discover all projects: From the workspace root,
prekrecursively searches all subdirectories for additional.pre-commit-config.yamlfiles. Each one becomes a separate project.Git repository boundary: The search stops at the git repository root (
.gitdirectory) to avoid including unrelated projects.Note: The workspace root is not necessarily the same as the git repository root, a workspace can exist within a subdirectory of a git repository.
Note: The current working directory determines the workspace root discovery.
prekstarts searching from your current location and stops at the first.pre-commit-config.yamlfile found while traversing up the directory tree. Running from different directories may discover different workspace roots. Useprek -C <dir>to change the working directory before execution.Project Organization
Example Structure
In this example:
my-monorepo/is the workspace rootdocs/,src/,src/backend/, andfrontend/are individual projects.pre-commit-config.yamlfileExecution Model
File Collection
When running in workspace mode:
prekcollects all files within the workspace root directoryHook Execution
For each project:
Execution Order
Projects are executed from deepest to shallowest:
src/backend/(deepest)src/docs/frontend/my-monorepo/(root, last)This ensures that more specific configurations (deeper projects) take precedence over general ones.
Note: Files in subprojects will be processed multiple times - once for each project in the hierarchy that contains them. For example, a file in
src/backend/will be checked by hooks insrc/backend/, thensrc/, then the workspace root.Example Output
When running
prek runon the example structure above, you might see output like this:Notice how:
src/backend/are processed by both thesrc/backend/project and thesrc/projectCommand Line Usage
The
-C <dir>or--cd <dir>option automatically changes to the specified directory before running, allowing you to target specific projects from any location in the workspace.Note: When using
prek install, only the workspace root configuration'sdefault_install_hook_typeswill be honored. Nested project configurations are not considered during installation.Project and Hook Selection
In workspace mode, you can selectively run hooks from specific projects or skip certain projects/hooks using flexible selector syntax.
Selector Syntax
The selector syntax has three different forms:
<hook-id>: Matches all hooks with the given ID across all projects.<project-path>/: Matches all hooks from the specified project and its subprojects.<project-path>:<hook-id>: Matches only the specified hook from the specified project.Selectors can be used to select specific hooks or projects, and combined with
--skipto exclude certain hooks or projects.Note:
<project-path>can be a relative path, which is then resolved relative to the current working directory.Note that the trailing slash
/in a<project-path>is important, if a selector does not contain a slash, it is interpreted as a hook ID.Running Specific Hooks or Projects
Examples:
Skipping Projects or Hooks
You can skip specific projects or hooks using the
--skipoption, with the same syntax as for selecting projects or hooks.Examples:
Note: Selecting a project includes all its subprojects unless explicitly skipped. Skipping a project also skips all its subprojects.
Note: The
PREK_SKIPorSKIPenvironment variable can be used as an alternative to--skip. Multiple values should be comma-delimited:Precedence rules for
--skipcommand line options and environment variables are:--skip>PREK_SKIP>SKIP.Advanced Examples
Single Config Mode
When you specify a configuration file using the
-cor--configparameter, workspace mode is disabled and only the specified configuration file is used. This mode provides traditional pre-commit behavior similar to the original pre-commit tool.In single config mode:
Usage Examples
Key Differences: Workspace vs Single Config
.pre-commit-config.yamlfilesMigration from Single Config
To migrate an existing single-config setup to workspace mode:
.pre-commit-config.yamlto repository root.pre-commit-config.yamlin subdirectories as neededfiles/excludepatterns to be project-relativeDebugging
Limitations (TODO)
SKIPPEDstatus.The workspace mode provides powerful organization capabilities while maintaining backward compatibility with existing single-config workflows.