From 4ee857a9f1c9153b944a2f48a89f35d9657b2ca5 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 13 Nov 2026 03:41:54 +0000 Subject: populate git: refuse work trees whose .git names places elsewhere A .git directory names places elsewhere in more ways than being a symlink or a file: core.worktree, symlinks to a configuration, to objects, or to refs elsewhere, a commondir file naming another repository, and linked work trees. Git's commands follow them, so fetching, resetting, setting the remote's URL, and cleaning change what is elsewhere: with core.worktree, git clean removes everything in the work tree it names. And Git runs commands the configuration names, like core.fsmonitor, and hooks. Populate only uses a work tree whose .git directory has no symlinks, no commondir file, no linked work trees, and only configuration that git clone and populate write, where submodules' repositories may have their work tree in the work tree. Otherwise populating fails with an error telling what's wrong, unless the new option reclone replaces the work tree by a fresh clone. Git runs without hooks and without fsmonitor in any case. The work tree also gets reset to the commit if HEAD is there already: a lock file rewritten in place, or created and staged by Nix, stays otherwise once the source stops drawing inputs. A safety scenario refuses work trees with core.worktree, a symlinked configuration, a commondir file, and core.fsmonitor, replaces them with reclone, and checks that a hook doesn't run. A git scenario stops drawing inputs and checks that the work tree is clean. --- lib/types/populate.nix | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') diff --git a/lib/types/populate.nix b/lib/types/populate.nix index 1a18b62..56b0292 100644 --- a/lib/types/populate.nix +++ b/lib/types/populate.nix @@ -258,6 +258,10 @@ ref = lib.mkOption { type = lib.types.str; # TODO lib.types.git.ref }; + reclone = lib.mkOption { + default = false; + type = lib.types.bool; + }; rewriteLock = lib.mkOption { default = true; type = lib.types.bool; -- cgit v1.3.1