Skip to content

Commit 2132c2f

Browse files
committed
fix(nix): let commits succeed in worktrees without a loaded dev shell
prek installs the hooks into the git common dir, so every worktree shares them, but each hook reads the worktree's own untracked .pre-commit-config.yaml symlink. That symlink only appears once the dev shell has loaded, so in a fresh worktree (for example one created outside `git wt`, which skips `direnv allow`) every commit aborted with "config file not found". git-hooks.nix exposes no option for prek's --allow-missing-config, so the dev shell now reinstalls the hooks with it whenever an installed hook lacks the flag. Worktrees with a loaded shell still run every hook.
1 parent 4dcf7f5 commit 2132c2f

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

‎nix/dev-shell.nix‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ in
107107
108108
${lib.getExe config.packages.syncAgentSkills}
109109
${config.pre-commit.shellHook}
110+
111+
# The hooks live in the git common dir, so every worktree shares them,
112+
# but each reads its worktree's untracked config symlink. A worktree
113+
# whose dev shell has never loaded has no such symlink, and without
114+
# `--allow-missing-config` every commit there aborts. git-hooks.nix has
115+
# no option for the flag, so reinstall with it, comparing before writing
116+
# as git-hooks.nix does.
117+
for stage in ${lib.escapeShellArgs config.pre-commit.settings.installStages}; do
118+
hookFile=$(${lib.getExe config.pre-commit.settings.gitPackage} rev-parse --path-format=absolute --git-path "hooks/$stage")
119+
if ! grep -q -- --skip-on-missing-config "$hookFile" 2>/dev/null; then
120+
${lib.getExe config.pre-commit.settings.package} install \
121+
-c ${config.pre-commit.settings.configPath} -t "$stage" --allow-missing-config >/dev/null
122+
fi
123+
done
110124
''
111125
+ gitWtHook;
112126
};

0 commit comments

Comments
 (0)