You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<h2id="automatically-enabling-pre-commit-on-repositories"> automatically enabling pre-commit on repositories <small><ahref="#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
+
<h2id="usage-with-git-254-hook-configuration"> usage with git 2.54+ hook configuration <small><ahref="#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><ahref="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>
<spanclass="c1"># please follow that naming scheme for future compatibility with `pre-commit install`</span>
1219
+
1220
+
<spanclass="c1"># an example with pre-push:</span>
1221
+
<spanclass="c1">#</span>
1222
+
<spanclass="c1"># git config set hook.pre-commit.pre-push.event pre-push</span>
1223
+
<spanclass="c1"># git config set hook.pre-commit.pre-push.command 'pre-commit hook-impl --hook-type pre-push --'</span>
1224
+
</pre></div>
1225
+
<p><code>pre-commit hook-impl</code> is a "hidden" implementation command with these options:</p>
1226
+
<ul>
1227
+
<li><code>--hook-type ...</code>: the <ahref="#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
+
<h3id="global-installation-of-pre-commit"> "global" installation of pre-commit <small><ahref="#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
<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
+
<h3id="always-running-a-hook-on-all-files"> always running a hook on all files <small><ahref="#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>
git<spanclass="w"></span>config<spanclass="w"></span><spanclass="nb">set</span><spanclass="w"></span>hook.pre-commit.pre-commit-always.command<spanclass="w"></span><spanclass="s1">'pre-commit run hookid --hook-stage pre-commit --all-files'</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
+
<h2id="automatically-enabling-pre-commit-on-repositories"> automatically enabling pre-commit on repositories <small><ahref="#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
0 commit comments