Skip to content

Commit ee0c7c5

Browse files
Deployed to github pages
1 parent 87bce67 commit ee0c7c5

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

index.html

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ <h2 id="quick-start"> Quick start <small><a href="#quick-start" class="text-d
134134
<li><code>pre-commit --version</code> should show you what version you're using</li>
135135
</ul>
136136
<div class="highlight pre-commit"><pre><span></span>$ pre-commit --version
137-
pre-commit 4.5.1
137+
pre-commit 4.6.0
138138
</pre></div>
139139
<h3 id="2-add-a-pre-commit-configuration"> 2. Add a pre-commit configuration <small><a href="#2-add-a-pre-commit-configuration" class="text-decoration-none"></a></small></h3> <ul>
140140
<li>create a file named <code>.pre-commit-config.yaml</code></li>
@@ -1202,7 +1202,54 @@ <h3 id="codepre-commit-hazmat-n1code"> <code>pre-commit hazmat n1</code> <sma
12021202
<span class="w"> </span><span class="nt">entry</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">pre-commit hazmat n1 example-bin --arg1 --</span>
12031203
<span class="w"> </span><span class="nt">args</span><span class="p">:</span><span class="w"> </span><span class="p p-Indicator">[]</span>
12041204
</pre></div>
1205-
<h2 id="automatically-enabling-pre-commit-on-repositories"> automatically enabling pre-commit on repositories <small><a href="#automatically-enabling-pre-commit-on-repositories" class="text-decoration-none"></a></small></h2> <p><code>pre-commit init-templatedir</code> can be used to set up a skeleton for <code>git</code>'s
1205+
<h2 id="usage-with-git-254-hook-configuration"> usage with git 2.54+ hook configuration <small><a href="#usage-with-git-254-hook-configuration" class="text-decoration-none"></a></small></h2> <p><em>new in 4.6.0</em>: pre-commit improved support for <code>git config</code>-based hooks.
1206+
a later version will change <code>pre-commit install</code> to use this approach.</p>
1207+
<p><a href="https://github.blog/open-source/git/highlights-from-git-2-54/#h-config-based-hooks">git 2.54</a> introduced a new way to install git hook tools via <code>git config</code>.</p>
1208+
<p>the basic gist is the following enables a hook in a git repo:</p>
1209+
<div class="highlight bash"><pre><span></span>git<span class="w"> </span>config<span class="w"> </span><span class="nb">set</span><span class="w"> </span>hook.&lt;name&gt;.event<span class="w"> </span>pre-push
1210+
git<span class="w"> </span>config<span class="w"> </span><span class="nb">set</span><span class="w"> </span>hook.&lt;name&gt;.command<span class="w"> </span><span class="s1">&#39;some command here&#39;</span>
1211+
</pre></div>
1212+
<p>an example setup with <code>pre-commit</code> might look like:</p>
1213+
<div class="highlight bash"><pre><span></span><span class="c1"># note, the &quot;hook&quot; name here is `pre-commit.pre-commit`</span>
1214+
<span class="c1"># for the `pre-commit` &quot;tool&quot; and the `pre-commit` &quot;event&quot;</span>
1215+
git<span class="w"> </span>config<span class="w"> </span><span class="nb">set</span><span class="w"> </span>hook.pre-commit.pre-commit.event<span class="w"> </span>pre-commit
1216+
git<span class="w"> </span>config<span class="w"> </span><span class="nb">set</span><span class="w"> </span>hook.pre-commit.pre-commit.command<span class="w"> </span><span class="s1">&#39;pre-commit hook-impl --hook-type pre-commit --&#39;</span>
1217+
1218+
<span class="c1"># please follow that naming scheme for future compatibility with `pre-commit install`</span>
1219+
1220+
<span class="c1"># an example with pre-push:</span>
1221+
<span class="c1">#</span>
1222+
<span class="c1"># git config set hook.pre-commit.pre-push.event pre-push</span>
1223+
<span class="c1"># git config set hook.pre-commit.pre-push.command &#39;pre-commit hook-impl --hook-type pre-push --&#39;</span>
1224+
</pre></div>
1225+
<p><code>pre-commit hook-impl</code> is a &quot;hidden&quot; implementation command with these options:</p>
1226+
<ul>
1227+
<li><code>--hook-type ...</code>: the <a href="#supported-git-hooks">hook type</a> to use</li>
1228+
<li><code>--skip-on-missing-config</code>: silently pass when a config is missing</li>
1229+
</ul>
1230+
<p>some interesting applications of this:</p>
1231+
<h3 id="global-installation-of-pre-commit"> &quot;global&quot; installation of pre-commit <small><a href="#global-installation-of-pre-commit" class="text-decoration-none"></a></small></h3> <p>with <code>git config set --global ...</code> this can automatically enable pre-commit
1232+
for all repositories:</p>
1233+
<div class="highlight bash"><pre><span></span>git<span class="w"> </span>config<span class="w"> </span><span class="nb">set</span><span class="w"> </span>--global<span class="w"> </span>hook.pre-commit.pre-commit.event<span class="w"> </span>pre-commit
1234+
git<span class="w"> </span>config<span class="w"> </span><span class="nb">set</span><span class="w"> </span>--global<span class="w"> </span>hook.pre-commit.pre-commit.command<span class="w"> </span><span class="s1">&#39;pre-commit hook-impl --hook-type pre-commit --skip-on-missing-config --&#39;</span>
1235+
</pre></div>
1236+
<ul>
1237+
<li>this setup <strong>not recommended</strong> as it can lead to accidentally running hooks
1238+
when interacting with an untrusted repository.</li>
1239+
<li><code>--skip-on-missing-config</code> is recommended here as arbitrary git repositories
1240+
may not have a <code>.pre-commit-config.yaml</code>.</li>
1241+
</ul>
1242+
<h3 id="always-running-a-hook-on-all-files"> always running a hook on all files <small><a href="#always-running-a-hook-on-all-files" class="text-decoration-none"></a></small></h3> <p>since you can configure pre-commit as many times as you want you <em>could</em> invoke
1243+
pre-commit to run a particular hook always and on all files</p>
1244+
<div class="highlight bash"><pre><span></span>git<span class="w"> </span>config<span class="w"> </span><span class="nb">set</span><span class="w"> </span>hook.pre-commit.pre-commit-always.event<span class="w"> </span>pre-commit
1245+
git<span class="w"> </span>config<span class="w"> </span><span class="nb">set</span><span class="w"> </span>hook.pre-commit.pre-commit-always.command<span class="w"> </span><span class="s1">&#39;pre-commit run hookid --hook-stage pre-commit --all-files&#39;</span>
1246+
</pre></div>
1247+
<p><em>note</em>: this is not recommended as it has the tendancy to be slow and deviates
1248+
from the normal expectations of pre-commit.</p>
1249+
<h2 id="automatically-enabling-pre-commit-on-repositories"> automatically enabling pre-commit on repositories <small><a href="#automatically-enabling-pre-commit-on-repositories" class="text-decoration-none"></a></small></h2> <p><em>note</em>: if you are on a new-enough version of <code>git</code> you may want to use
1250+
<a href="#global-installation-of-pre-commit">this approach</a> instead.</p>
1251+
<hr />
1252+
<p><code>pre-commit init-templatedir</code> can be used to set up a skeleton for <code>git</code>'s
12061253
<code>init.templateDir</code> option. This means that any newly cloned repository will
12071254
automatically have the hooks set up without the need to run
12081255
<code>pre-commit install</code>.</p>

0 commit comments

Comments
 (0)