125
125
processedHooks =
126
126
mapAttrsToList ( id : value : value . raw // { inherit id ; } ) enabledHooks ;
127
127
128
- hooksFile =
129
- writeText "pre-commit-hooks.json" ( builtins . toJSON processedHooks ) ;
130
128
configFile =
131
129
runCommand "pre-commit-config.json" {
132
130
buildInputs = [ pkgs . jq ] ;
@@ -140,26 +138,12 @@ let
140
138
} >$out
141
139
'' ;
142
140
143
- hooks =
144
- runCommand "pre-commit-hooks-dir" { buildInputs = [ git ] ; } ''
145
- HOME=$PWD
146
- mkdir -p $out
147
- ln -s ${ hooksFile } $out/.pre-commit-hooks.yaml
148
- cd $out
149
- git config --global user.email "you@example.com"
150
- git config --global user.name "Your Name"
151
- git init
152
- git add .
153
- git commit -m "init"
154
- '' ;
155
-
156
141
run =
157
142
runCommand "pre-commit-run" { buildInputs = [ git ] ; } ''
158
143
set +e
159
144
HOME=$PWD
160
145
cp --no-preserve=mode -R ${ cfg . rootSrc } src
161
- unlink src/.pre-commit-hooks || true
162
- ln -fs ${ hooks } src/.pre-commit-hooks
146
+ ln -fs ${ configFile } src/.pre-commit-config.yaml
163
147
cd src
164
148
rm -rf src/.git
165
149
git init
@@ -289,10 +273,8 @@ in {
289
273
repos =
290
274
[
291
275
{
292
- repo = ".pre-commit-hooks/" ;
293
- rev = "master" ;
294
- hooks =
295
- mapAttrsToList ( id : _value : { inherit id ; } ) enabledHooks ;
276
+ repo = "local" ;
277
+ hooks = processedHooks ;
296
278
}
297
279
] ;
298
280
} // lib . optionalAttrs ( cfg . excludes != [ ] ) {
@@ -306,41 +288,20 @@ in {
306
288
# This happens in pure shells, including lorri
307
289
echo 1>&2 "WARNING: nix-pre-commit-hooks: git command not found; skipping installation."
308
290
else
309
- local doInstall=false
310
-
311
291
# These update procedures compare before they write, to avoid
312
292
# filesystem churn. This improves performance with watch tools like lorri
313
293
# and prevents installation loops by via lorri.
314
294
315
- if readlink .pre-commit-hooks >/dev/null \
316
- && [[ $(readlink .pre-commit-hooks ) == ${ hooks } ]]; then
295
+ if readlink .pre-commit-config.yaml >/dev/null \
296
+ && [[ $(readlink .pre-commit-config.yaml ) == ${ configFile } ]]; then
317
297
echo 1>&2 "nix-pre-commit-hooks: hooks up to date"
318
298
else
319
299
echo 1>&2 "nix-pre-commit-hooks: updating $PWD repo"
320
300
321
- [ -L .pre-commit-hooks ] && unlink .pre-commit-hooks
322
- ln -s ${ hooks } .pre-commit-hooks
323
-
324
- doInstall=true
325
- fi
326
-
327
- if cmp ${ configFile } .pre-commit-config.yaml &>/dev/null; then
328
- echo 1>&2 "nix-pre-commit-hooks: config up to date"
329
- else
330
- echo 1>&2 "nix-pre-commit-hooks: updating $PWD config"
331
-
332
- # This can't be a symlink because its path is not constant,
333
- # thus can not be committed and is invisible to pre-commit.
334
- rm -f .pre-commit-config.yaml
335
- cat ${ configFile } >.pre-commit-config.yaml
336
-
337
- doInstall=true
338
- fi
301
+ [ -L .pre-commit-config.yaml ] && unlink .pre-commit-config.yaml
302
+ ln -s ${ configFile } .pre-commit-config.yaml
339
303
340
- if $doInstall; then
341
304
pre-commit install
342
- # this is needed as the hook repo configuration is cached
343
- pre-commit clean
344
305
fi
345
306
fi
346
307
'' ;
0 commit comments