GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — pre-commit.github.io/index.mako at real_master · ViViDboarder/pre-commit.github.io Expand file tree/ Copy pathindex.makoMore file actions 1441 lines (1125 loc) · 49.1 KB / Copy pathindex.makoFile metadata and controls1441 lines (1125 loc) · 49.1 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 ## -*- coding: utf-8 -*- <%! from template_lib import md %> <%inherit file="base.mako" /> <div class="row"> <div class="col-sm-3 hidden-xs pc-sidebar"> <ul class="nav nav-pills nav-stacked pc-sidenav" data-spy="affix" data-offset-top="400"> <li class="active"><a href="#intro">Introduction</a></li> <li><a href="#install">Installation</a></li> <li><a href="#plugins">Adding plugins</a></li> <li><a href="#usage">Usage</a></li> <li><a href="#new-hooks">Creating new hooks</a></li> <li><a href="#cli">Command line interface</a></li> <li><a href="#advanced">Advanced features</a></li> <li><a href="#contributing">Contributing</a></li> </ul> </div> <div class="col-sm-9"> <div id="intro"> <div class="page-header"><h1>Introduction</h1></div> ${md(''' Git hook scripts are useful for identifying simple issues before submission to code review. We run our hooks on every commit to automatically point out issues in code such as missing semicolons, trailing whitespace, and debug statements. By pointing these issues out before code review, this allows a code reviewer to focus on the architecture of a change while not wasting time with trivial style nitpicks. As we created more libraries and projects we recognized that sharing our pre-commit hooks across projects is painful. We copied and pasted unwieldy bash scripts from project to project and had to manually change the hooks to work for different project structures. We believe that you should always use the best industry standard linters. Some of the best linters are written in languages that you do not use in your project or have installed on your machine. For example scss-lint is a linter for SCSS written in Ruby. If you’re writing a project in node you should be able to use scss-lint as a pre-commit hook without adding a Gemfile to your project or understanding how to get scss-lint installed. We built pre-commit to solve our hook issues. It is a multi-language package manager for pre-commit hooks. You specify a list of hooks you want and pre-commit manages the installation and execution of any hook written in any language before every commit. pre-commit is specifically designed to not require root access. If one of your developers doesn’t have node installed but modifies a JavaScript file, pre-commit automatically handles downloading and building node to run eslint without root. ''')} </div> <div id="install"> <div class="page-header"><h1>Installation</h1></div> ${md(''' Before you can run hooks, you need to have the pre-commit package manager installed. Using pip: ```bash pip install pre-commit ``` Non-administrative installation: - _to upgrade: run again, to uninstall: pass `uninstall` to python_ - _does not work on platforms without symlink support (windows)_ ```bash curl https://pre-commit.com/install-local.py | python - ``` In a python project, add the following to your requirements.txt (or requirements-dev.txt): ``` pre-commit ``` Using [homebrew](https://brew.sh): ```bash brew install pre-commit ``` Using [conda](https://conda.io) (via [conda-forge](https://conda-forge.org)): ```bash conda install -c conda-forge pre-commit ``` ## Quick start ### 1. Install pre-commit - follow the [install](#install) instructions above - `pre-commit --version` should show you what version you're using ```console $ pre-commit --version pre-commit 1.18.1 ``` ### 2. Add a pre-commit configuration - create a file named `.pre-commit-config.yaml` - you can generate a very basic configuration using [`pre-commit sample-config`](#pre-commit-sample-config) - the full set of options for the configuration are listed [below](#plugins) - this example uses a formatter for python code, however `pre-commit` works for any programming language - other [supported hooks](hooks.html) are available ```yaml repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v2.3.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/psf/black rev: 19.3b0 hooks: - id: black ``` ### 3. Install the git hook scripts - run `pre-commit install` to set up the git hook scripts ```console $ pre-commit install pre-commit installed at .git/hooks/pre-commit ``` - now `pre-commit` will run automatically on `git commit`! ### 4. (optional) Run against all the files - it's usually a good idea to run the hooks against all of the files when adding new hooks (usually `pre-commit` will only run on the changed files during git hooks) ```pre-commit $ pre-commit run --all-files [INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks. [INFO] Initializing environment for https://github.com/psf/black. [INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks. [INFO] Once installed this environment will be reused. [INFO] This may take a few minutes... [INFO] Installing environment for https://github.com/psf/black. [INFO] Once installed this environment will be reused. [INFO] This may take a few minutes... Check Yaml...............................................................Passed Fix End of Files.........................................................Passed Trim Trailing Whitespace.................................................Failed hookid: trailing-whitespace Files were modified by this hook. Additional output: Fixing sample.py black....................................................................Passed ``` - oops! looks like I had some trailing whitespace - consider running that in [CI](#usage-in-continuous-integration) too ''')} </div> <div id="plugins"> <div class="page-header"> <h1>Adding pre-commit plugins to your project</h1> </div> ${md(''' Once you have pre-commit installed, adding pre-commit plugins to your project is done with the `.pre-commit-config.yaml` configuration file. Add a file called `.pre-commit-config.yaml` to the root of your project. The pre-commit config file describes what repositories and hooks are installed. ## .pre-commit-config.yaml - top level _new in 1.0.0_: The default configuration file top-level was changed from a list to a map. If you're using an old version of pre-commit, the top-level list is the same as the value of [`repos`](#pre-commit-configyaml---repos). If you'd like to migrate to the new configuration format, run [`pre-commit migrate-config`](#pre-commit-migrate-config) to automatically migrate your configuration. ```table =r= =c= `repos` =c= A list of [repository mappings](#pre-commit-configyaml---repos). =r= =c= `default_language_version` =c= (optional: default `{}`) a mapping from language to the default `language_version` that should be used for that language. This will only override individual hooks that do not set `language_version`. For example to use `python3.7` for `language: python` hooks: ```yaml default_language_version: python: python3.7 ``` _new in 1.14.0_ =r= =c= `default_stages` =c= (optional: default (all stages)) a configuration-wide default for the `stages` property of hooks. This will only override individual hooks that do not set `stages`. For example: ```yaml default_stages: [commit, push] ``` _new in 1.14.0_ =r= =c= `exclude` =c= (optional: default `^$`) global file exclude pattern. _new in 1.1.0_. =r= =c= `fail_fast` =c= (optional: default `false`) set to `true` to have pre-commit stop running hooks after the first failure. _new in 1.1.0_. =r= =c= `minimum_pre_commit_version` =c= (optional: default `'0'`) require a minimum version of pre-commit. _new in 1.15.0_. ``` A sample top-level: ```yaml exclude: '^$' fail_fast: false repos: - ... ``` ## .pre-commit-config.yaml - repos The repository mapping tells pre-commit where to get the code for the hook from. ```table =r= =c= `repo` =c= the repository url to `git clone` from =r= =c= `rev` =c= the revision or tag to clone at. _new in 1.7.0_: previously `sha` =r= =c= `hooks` =c= A list of [hook mappings](#pre-commit-configyaml---hooks). ``` A sample repository with all defaults present: ```yaml repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v1.2.3 hooks: - ... ``` ## .pre-commit-config.yaml - hooks The hook mapping configures which hook from the repository is used and allows for customization. All optional keys will receive their default from the repository's configuration. ```table =r= =c= `id` =c= which hook from the repository to use. =r= =c= `alias` =c= (optional) allows the hook to be referenced using an additional id when using `pre-commit run <hookid>`. _new in 1.14.0_. =r= =c= `name` =c= (optional) override the name of the hook - shown during hook execution. =r= =c= `language_version` =c= (optional) override the language version for the hook. See [Overriding Language Version](#overriding-language-version). =r= =c= `files` =c= (optional) override the default pattern for files to run on. =r= =c= `exclude` =c= (optional) file exclude pattern. =r= =c= `types` =c= (optional) override the default file types to run on. See [Filtering files with types](#filtering-files-with-types). _new in 0.15.0_. =r= =c= `exclude_types` =c= (optional) file types to exclude. _new in 0.15.0_. =r= =c= `args` =c= (optional) list of additional parameters to pass to the hook. =r= =c= `stages` =c= (optional) confines the hook to the `commit`, `push`, `prepare-commit-msg`, `commit-msg`, or `manual` stage. See [Confining hooks to run at certain stages](#confining-hooks-to-run-at-certain-stages). =r= =c= `additional_dependencies` =c= (optional) a list of dependencies that will be installed in the environment where this hook gets run. One useful application is to install plugins for hooks such as `eslint`. _new in 0.6.6_. =r= =c= `always_run` =c= (optional) if `true`, this hook will run even if there are no matching files. _new in 0.7.2_. =r= =c= `verbose` =c= (optional) if `true`, forces the output of the hook to be printed even when the hook passes. _new in 1.6.0_. =r= =c= `log_file` =c= (optional) if present, the hook output will additionally be written to a file. _new in 0.14.0_. ``` One example of a complete configuration: ```yaml repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v1.2.3 hooks: - id: trailing-whitespace ``` This configuration says to download the pre-commit-hooks project and run its trailing-whitespace hook. ## Updating hooks automatically You can update your hooks to the latest version automatically by running `pre-commit autoupdate`. This will bring the hooks to the latest tag on the master branch. ''')} </div> <div id="usage"> <div class="page-header"><h1>Usage</h1></div> ${md(''' Run `pre-commit install` to install pre-commit into your git hooks. pre-commit will now run on every commit. Every time you clone a project using pre-commit running `pre-commit install` should always be the first thing you do. If you want to manually run all pre-commit hooks on a repository, run `pre-commit run --all-files`. To run individual hooks use `pre-commit run <hook_id>`. The first time pre-commit runs on a file it will automatically download, install, and run the hook. Note that running a hook for the first time may be slow. For example: If the machine does not have node installed, pre-commit will download and build a copy of node. ```pre-commit $ pre-commit install pre-commit installed at /home/asottile/workspace/pytest/.git/hooks/pre-commit $ git commit -m "Add super awesome feature" black....................................................................Passed blacken-docs.........................................(no files to check)Skipped Trim Trailing Whitespace.................................................Passed Fix End of Files.........................................................Passed Check Yaml...........................................(no files to check)Skipped Debug Statements (Python)................................................Passed Flake8...................................................................Passed Reorder python imports...................................................Passed pyupgrade................................................................Passed rst ``code`` is two backticks........................(no files to check)Skipped rst..................................................(no files to check)Skipped changelog filenames..................................(no files to check)Skipped [master 146c6c2c] Add super awesome feature 1 file changed, 1 insertion(+) ``` ''')} </div> <div id="new-hooks"> <div class="page-header"><h1>Creating new hooks</h1></div> ${md(''' pre-commit currently supports hooks written in [many languages](#supported-languages). As long as your git repo is an installable package (gem, npm, pypi, etc.) or exposes an executable, it can be used with pre-commit. Each git repo can support as many languages/hooks as you want. The hook must exit nonzero on failure or modify files in the working directory _(since 0.6.3)_. A git repo containing pre-commit plugins must contain a .pre-commit-hooks.yaml file that tells pre-commit: ```table =r= =c= `id` =c= the id of the hook - used in pre-commit-config.yaml. =r= =c= `name` =c= the name of the hook - shown during hook execution. =r= =c= `entry` =c= the entry point - the executable to run. `entry` can also contain arguments that will not be overridden such as `entry: autopep8 -i`. =r= =c= `language` =c= the language of the hook - tells pre-commit how to install the hook. =r= =c= `files` =c= (optional: default `''`) the pattern of files to run on. _new in 0.15.0_: now optional. =r= =c= `exclude` =c= (optional: default `^$`) exclude files that were matched by `files`. =r= =c= `types` =c= (optional: default `[file]`) list of file types to run on. See [Filtering files with types](#filtering-files-with-types). _new in 0.15.0_. =r= =c= `exclude_types` =c= (optional: default `[]`) exclude files that were matched by `types`. _new in 0.15.0_. =r= =c= `always_run` =c= (optional: default `false`) if `true` this hook will run even if there are no matching files. _new in 0.7.2_. =r= =c= `verbose` =c= (optional) if `true`, forces the output of the hook to be printed even when the hook passes. _new in 1.6.0_. =r= =c= `pass_filenames` =c= (optional: default `true`) if `true` this hook must take filenames as positional arguments. _new in 0.14.0_. =r= =c= `require_serial` =c= (optional: default `false`) if `true` this hook will execute using a single process instead of in parallel. _new in 1.13.0_. =r= =c= `description` =c= (optional: default `''`) description of the hook. used for metadata purposes only. =r= =c= `language_version` =c= (optional: default `default`) see [Overriding language version](#overriding-language-version). =r= =c= `minimum_pre_commit_version` =c= (optional: default `'0'`) allows one to indicate a minimum compatible pre-commit version. _new in 0.6.7_. =r= =c= `args` =c= (optional: default `[]`) list of additional parameters to pass to the hook. ``` For example: ```yaml - id: trailing-whitespace name: Trim Trailing Whitespace description: This hook trims trailing whitespace. entry: trailing-whitespace-fixer language: python types: [text] ``` _new in 0.12.0_: Prior to 0.12.0 the file was `hooks.yaml` (now `.pre-commit-hooks.yaml`). For backwards compatibility it is suggested to provide both files or suggest users use `pre-commit>=0.12.0`. ## Developing hooks interactively Since the `repo` property of `.pre-commit-config.yaml` can refer to anything that `git clone ...` understands, it's often useful to point it at a local directory while developing hooks. [`pre-commit try-repo`](#pre-commit-try-repo) streamlines this process by enabling a quick way to try out a repository. Here's how one might work interactively: _new in 1.14.0_: a commit is no longer necessary to `try-repo` on a local directory. `pre-commit` will clone any uncommitted changes. ```pre-commit ~/work/hook-repo $ git checkout origin/master -b feature # ... make some changes # new in 1.14.0: a commit is no longer necessary for `try-repo` # In another terminal or tab ~/work/other-repo $ pre-commit try-repo ../hook-repo foo --verbose --all-files =============================================================================== Using config: =============================================================================== repos: - repo: ../hook-repo rev: 84f01ac09fcd8610824f9626a590b83cfae9bcbd hooks: - id: foo =============================================================================== [INFO] Initializing environment for ../hook-repo. [foo] Foo................................................................Passed hookid: foo Hello from foo hook! ``` ## Supported languages - [docker](#docker) - [docker_image](#docker_image) - [fail](#fail) - [golang](#golang) - [node](#node) - [python](#python) - [python_venv](#python_venv) - [ruby](#ruby) - [rust](#rust) - [swift](#swift) - [pcre](#pcre) - [pygrep](#pygrep) - [script](#script) - [system](#system) ### docker _new in 0.10.0_ The hook repository must have a `Dockerfile`. It will be installed via `docker build .`. Running Docker hooks requires a running Docker engine on your host. For configuring Docker hooks, your `entry` should correspond to an executable inside the Docker container, and will be used to override the default container entrypoint. Your Docker `CMD` will not run when pre-commit passes a file list as arguments to the run container command. Docker allows you to use any language that's not supported by pre-commit as a builtin. __Support:__ docker hooks are known to work on any system which has a working `docker` executable. It has been tested on linux and macOS. Hooks that are run via `boot2docker` are known to be unable to make modifications to files. See [this repository](https://github.com/pre-commit/pre-commit-docker-flake8) for an example Docker-based hook. ### docker_image _new in 0.18.0_ A more lightweight approach to `docker` hooks. The `docker_image` "language" uses existing docker images to provide hook executables. `docker_image` hooks can be conveniently configured as [local](#repository-local-hooks) hooks. The `entry` specifies the docker tag to use. If an image has an `ENTRYPOINT` defined, nothing special is needed to hook up the executable. If the container does not specify an `ENTRYPOINT` or you want to change the entrypoint you can specify it as well in your `entry`. For example: ```yaml - id: dockerfile-provides-entrypoint name: ... language: docker_image entry: my.registry.example.com/docker-image-1:latest - id: dockerfile-no-entrypoint-1 name: ... language: docker_image entry: --entrypoint my-exe my.registry.example.com/docker-image-2:latest # Alternative equivalent solution - id: dockerfile-no-entrypoint-2 name: ... language: docker_image entry: my.registry.example.com/docker-image-3:latest my-exe ``` ### fail _new in 1.11.0_ A lightweight `language` to forbid files by filename. The `fail` language is especially useful for [local](#repository-local-hooks) hooks. The `entry` will be printed when the hook fails. It is suggested to provide a brief description for `name` and more verbose fix instructions in `entry`. Here's an example which prevents any file except those ending with `.rst` from being added to the `changelog` directory: ```yaml - repo: local hooks: - id: changelogs-rst name: changelogs must be rst entry: changelog filenames must end in .rst language: fail files: 'changelog/.*(?<!\.rst)$' ``` ### golang _new in 0.12.0_ The hook repository must contain go source code. It will be installed via `go get ./...`. pre-commit will create an isolated `GOPATH` for each hook and the `entry` should match an executable which will get installed into the `GOPATH`'s `bin` directory. __Support:__ golang hooks are known to work on any system which has go installed. It has been tested on linux, macOS, and windows. ### node The hook repository must have a `package.json`. It will be installed via `npm install .`. The installed package will provide an executable that will match the `entry` – usually through `bin` in package.json. __Support:__ node hooks work without any system-level dependencies. It has been tested on linux and macOS and _may_ work under cygwin. _new in 1.5.0_: windows is now supported for node hooks. Currently python3 only due to [a bug in cpython](https://bugs.python.org/issue32539). ### python The hook repository must have a `setup.py`. It will be installed via `pip install .`. The installed package will provide an executable that will match the `entry` – usually through `console_scripts` or `scripts` in setup.py. __Support:__ python hooks work without any system-level dependencies. It has been tested on linux, macOS, windows, and cygwin. ### python_venv _new in 1.9.0_ An alternate implementation of the [python](#python) language which uses the python 3 [`venv`](https://docs.python.org/3/library/venv.html) module. On many systems you need to additionally install the `python3-venv` system package to use this language. This is otherwise a drop-in replacement for the `python` language for situations where [`virtualenv` may not work](https://github.com/pre-commit/pre-commit/issues/631). __Support:__ python hooks work without any system-level dependencies. It has been tested on linux, macOS, windows, and cygwin. Only python3 environments can be created with this language. ### ruby The hook repository must have a `*.gemspec`. It will be installed via `gem build *.gemspec && gem install *.gem`. The installed package will produce an executable that will match the `entry` – usually through `executables` in your gemspec. __Support:__ ruby hooks work without any system-level dependencies. It has been tested on linux and macOS and _may_ work under cygwin. ### rust _new in 1.10.0_ Rust hooks are installed using the system installation of [Cargo](https://github.com/rust-lang/cargo), Rust's official package manager. Hook repositories must have a `Cargo.toml` file which produces at least one binary ([example](https://github.com/chriskuehl/example-rust-pre-commit-hook)), whose name should match the `entry` definition for your hook. The repo will be installed via `cargo install --bins` (with the binaries stored in your pre-commit cache, not polluting your user-level Cargo installations). When specifying `additional_dependencies` for Rust, you can use the syntax `{package_name}:{package_version}` to specify a new library dependency (used to build _your_ hook repo), or the special syntax `cli:{package_name}:{package_version}` for a CLI dependency (built separately, with binaries made available for use by hooks). __Support:__ Rust hooks currently require a pre-existing Rust installation. It has been tested on linux, Windows, and macOS. ### swift _new in 0.11.0_ The hook repository must have a `Package.swift`. It will be installed via `swift build -c release`. The `entry` should match an executable created by building the repository. __Support:__ swift hooks are known to work on any system which has swift installed. It has been tested on linux and macOS. ### pcre _**deprecated**_: the pcre language will be removed in a later version. Use [pygrep](#pygrep) hooks instead (usually a drop-in replacement). "Perl Compatible Regular Expressions" – pcre hooks are a quick way to write a simple hook which prevents commits by file matching. Specify the regex as the `entry`. macos does not ship with a functioning `grep -P` so you'll need `brew install grep` for pcre hooks to function. __Support:__ pcre hooks work on any system which has a functioning `grep -P` (or in the case of macOS: `ggrep -P`). It has been tested on linux, macOS, windows, and cygwin. ### pygrep _new in 1.2.0_ A cross-platform python implementation of `grep` – pygrep hooks are a quick way to write a simple hook which prevents commits by file matching. Specify the regex as the `entry`. The `entry` may be any python [regular expression](#regular-expressions). For case insensitive regexes you can apply the `(?i)` flag as the start of your entry, or use `args: [-i]`. _new in 1.8.0_: For multiline matches, use `args: [--multiline]`. __Support:__ pygrep hooks are supported on all platforms which pre-commit runs on. ### script Script hooks provide a way to write simple scripts which validate files. The `entry` should be a path relative to the root of the hook repository. This hook type will not be given a virtual environment to work with – if it needs additional dependencies the consumer must install them manually. __Support:__ the support of script hooks depend on the scripts themselves. ### system System hooks provide a way to write hooks for system-level executables which don't have a supported language above (or have special environment requirements that don't allow them to run in isolation such as pylint). This hook type will not be given a virtual environment to work with – if it needs additional dependencies the consumer must install them manually. __Support:__ the support of system hooks depend on the executables. ''')} </div> <div id="cli"> <div class="page-header"><h1>Command line interface</h1></div> ${md(''' All pre-commit commands take the following options: - `--color {auto,always,never}`: whether to use color in output. Defaults to `auto`. _new in 1.18.0_: can be overridden by using `PRE_COMMIT_COLOR={auto,always,never}` or disabled using `TERM=dumb`. - `-c CONFIG`, `--config CONFIG`: path to alternate config file - `-h`, `--help`: show help and available options. ## pre-commit autoupdate [options] [](#pre-commit-autoupdate) Auto-update pre-commit config to the latest repos' versions. Options: - `--bleeding-edge`: update to the bleeding edge of `master` instead of the latest tagged version (the default behaviour). - `--repo REPO`: _new in 1.4.1_: Only update this repository. _new in 1.7.0_: This option may be specified multiple times. ## pre-commit clean [options] [](#pre-commit-clean) Clean out cached pre-commit files. Options: (no additional options) ## pre-commit gc [options] [](#pre-commit-gc) _new in 1.14.0_ Clean unused cached repos. `pre-commit` keeps a cache of installed hook repositories which grows over time. This command can be run periodically to clean out unused repos from the cache directory. Options: (no additional options) ## pre-commit init-templatedir DIRECTORY [options] [](#pre-commit-init-templatedir) _new in 1.18.0_ Install hook script in a directory intended for use with `git config init.templateDir`. Options: - `-t {pre-commit,pre-push,prepare-commit-msg,commit-msg}`, `--hook-type {pre-commit,pre-push,prepare-commit-msg,commit-msg}`: which hook type to install. Some example useful invocations: ```bash git config --global init.templateDir ~/.git-template pre-commit init-templatedir ~/.git-template ``` Now whenever a repository is cloned or created, it will have the hooks set up already! ## pre-commit install [options] [](#pre-commit-install) Install the pre-commit script. Options: - `-f`, `--overwrite`: Replace any existing git hooks with the pre-commit script. - `--install-hooks`: Also install environments for all available hooks now (rather than when they are first executed). See [`pre-commit install-hooks`](#pre-commit-install-hooks). - `-t {pre-commit,pre-push,prepare-commit-msg,commit-msg}`, `--hook-type {pre-commit,pre-push,prepare-commit-msg,commit-msg}`: Specify which hook type to install. - `--allow-missing-config`: Hook scripts will permit a missing configuration file. Some example useful invocations: - `pre-commit install`: Default invocation. Installs the pre-commit script alongside any existing git hooks. - `pre-commit install --install-hooks --overwrite`: Idempotently replaces existing git hook scripts with pre-commit, and also installs hook environments. ## pre-commit install-hooks [options] [](#pre-commit-install-hooks) Install all missing environments for the available hooks. Unless this command or `install --install-hooks` is executed, each hook's environment is created the first time the hook is called. Each hook is initialized in a separate environment appropriate to the language the hook is written in. See [supported languages](#supported-languages). This command does not install the pre-commit script. To install the script along with the hook environments in one command, use `pre-commit install --install hooks`. Options: (no additional options) ## pre-commit migrate-config [options] [](#pre-commit-migrate-config) _new in 1.0.0_ Migrate list configuration to the new map configuration format. Options: (no additional options) ## pre-commit run [hook-id] [options] [](#pre-commit-run) Run hooks. Options: - `[hook-id]`: specify a single hook-id to run only that hook. - `-a`, `--all-files`: run on all the files in the repo. - `--files [FILES [FILES ...]]`: specific filenames to run hooks on. - `--source SOURCE` + `--origin ORIGIN`: run against the files changed between `SOURCE...ORIGIN` in git. - `--show-diff-on-failure`: _new in 0.13.4_: when hooks fail, run `git diff` directly afterward. - `-v`, `--verbose`: produce hook output independent of success. Include hook ids in output. Some example useful invocations: - `pre-commit run`: this is what pre-commit runs by default when committing. This will run all hooks against currently staged files. - `pre-commit run --all-files`: run all the hooks against all the files. This is a useful invocation if you are using pre-commit in CI. - `pre-commit run flake8`: run the `flake8` hook against all staged files. - `git ls-files -- '*.py' | xargs pre-commit run --files`: run all hooks against all `*.py` files in the repository. - `pre-commit run --source HEAD^^^ --origin HEAD`: run against the files that have changed between `HEAD^^^` and `HEAD`. This form is useful when leveraged in a pre-receive hook. ## pre-commit sample-config [options] [](#pre-commit-sample-config) Produce a sample `.pre-commit-config.yaml`. Options: (no additional options) ## pre-commit try-repo REPO [options] [](#pre-commit-try-repo) _new in 1.3.0_ Try the hooks in a repository, useful for developing new hooks. `try-repo` can also be used for testing out a repository before adding it to your configuration. `try-repo` prints a configuration it generates based on the remote hook repository before running the hooks. Options: - `REPO`: required clonable hooks repository. Can be a local path on disk. - `--ref REF`: Manually select a ref to run against, otherwise the `HEAD` revision will be used. - `pre-commit try-repo` also supports all available options for [`pre-commit run`](#pre-commit-run). Some example useful invocations: - `pre-commit try-repo https://github.com/pre-commit/pre-commit-hooks`: runs all the hooks in the latest revision of `pre-commit/pre-commit-hooks`. - `pre-commit try-repo ../path/to/repo`: run all the hooks in a repository on disk. - `pre-commit try-repo ../pre-commit-hooks flake8`: run only the `flake8` hook configured in a local `../pre-commit-hooks` repository. - See [`pre-commit run`](#pre-commit-run) for more useful `run` invocations which are also supported by `pre-commit try-repo`. ## pre-commit uninstall [options] [](#pre-commit-uninstall) Uninstall the pre-commit script. Options: - `-t {pre-commit,pre-push,prepare-commit-msg,commit-msg}`, `--hook-type {pre-commit,pre-push,prepare-commit-msg,commit-msg}`: which hook type to uninstall. ''')} </div> <div id="advanced"> <div class="page-header"><h1>Advanced features</h1></div> ${md(''' ## Running in migration mode By default, if you have existing hooks `pre-commit install` will install in a migration mode which runs both your existing hooks and hooks for pre-commit. To disable this behavior, simply pass `-f` / `--overwrite` to the `install` command. If you decide not to use pre-commit, `pre-commit uninstall` will restore your hooks to the state prior to installation. ## Temporarily disabling hooks Not all hooks are perfect so sometimes you may need to skip execution of one or more hooks. pre-commit solves this by querying a `SKIP` environment variable. The `SKIP` environment variable is a comma separated list of hook ids. This allows you to skip a single hook instead of `--no-verify`ing the entire commit. ```console $ SKIP=flake8 git commit -m "foo" ``` ## pre-commit during commits Running hooks on unstaged changes can lead to both false-positives and false-negatives during committing. pre-commit only runs on the staged contents of files by temporarily saving the contents of your files at commit time and stashing the unstaged changes while running hooks. ## pre-commit during merges The biggest gripe we’ve had in the past with pre-commit hooks was during merge conflict resolution. When working on very large projects a merge often results in hundreds of committed files. I shouldn’t need to run hooks on all of these files that I didn’t even touch! This often led to running commit with `--no-verify` and allowed introduction of real bugs that hooks could have caught. pre-commit solves this by only running hooks on files that conflict or were manually edited during conflict resolution. This also includes files which were automatically merged by git. Git isn't perfect and this can often catch implicit conflicts (such as with removed python imports). ## pre-commit during push |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |