From 6b2491a410dfb7ffb33b15280a5861d4ab67e1da Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 13 Nov 2026 21:26:00 +0000 Subject: tests: a hook in a flake populate locks lock-hooks plants a .git in a file source that keeps it, with configuration a git source would use, but a post-index-change hook, which Nix's Git runs when it adds the lock file it writes into a git+file: flake. Drawing inputs refers to that flake as path:, so the hook doesn't run. --- tests/scenarios.nix | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'tests') diff --git a/tests/scenarios.nix b/tests/scenarios.nix index 990a99b..92f94fd 100644 --- a/tests/scenarios.nix +++ b/tests/scenarios.nix @@ -2313,6 +2313,48 @@ assert !(krops.isLocalTarget (targets.remote "/")); } ]; })) + # A .git that a file source keeps, with configuration a git source would + # use, but a hook, which Nix's Git runs when it adds the lock file it + # writes: populate's Git runs none, so git sources keep hooks, but + # drawing inputs refers to the flake as path:. + (s "lock-hooks" (let + elsewhere = "/var/krops-elsewhere"; + sources = alt // { + y.file = { + path = "/fixtures/filesrc"; + deleteExcluded = false; + filters = [ { type = "exclude"; pattern = "/.git"; } ]; + inputs.dep.follows = "alt"; + }; + }; + in { + isolate = true; + prepare = '' + rm -fR ${elsewhere} + mkdir -p ${elsewhere} + ''; + phases = [ + { + inherit sources; + # A repository tracking only flake.nix, so Nix adds the lock file, + # which runs post-index-change. + mutate = '' + git -C "$T"/y init -q + git -C "$T"/y add flake.nix + git -C "$T"/y -c user.name=x -c user.email=x@x commit -q -m x + printf '#! /bin/sh\ntouch ${elsewhere}/ran\n' > "$T"/y/.git/hooks/post-index-change + chmod +x "$T"/y/.git/hooks/post-index-change + ''; + } + { + inherit sources; + check = '' + test ! -e ${elsewhere}/ran || fail "a hook in a .git directory ran" + test -e "$T"/y/flake.lock || fail "y/flake.lock missing" + ''; + } + ]; + })) # A file in populate's state replaced by a symlink to a file outside. (s "state-key" (let sources.x.flake-input = { -- cgit v1.3.1