diff options
| author | tv <tv@krebsco.de> | 2026-11-13 20:27:48 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-13 21:59:07 +0100 |
| commit | b34f53d538c5afa95fd0dc6dd81b56e4995b80c2 (patch) | |
| tree | f8afac88dcb0a695f6eaf911fcdc7cdc36e62532 /tests/scenarios.nix | |
| parent | ef581c93f391919b35b903b93af45f33d90de15d (diff) | |
populate: check the hooks and submodules of Git work trees
git submodule update uses the .git of a submodule as it finds it in the
work tree: a repository of its own, with configuration that runs
commands, or a file naming a repository elsewhere. So git_problems
also requires each .git below the work tree to be a file naming a
repository in .git/modules. And it refuses hooks in .git/hooks, which
populate's Git doesn't run, but Nix's does, writing the lock file of a
flake in a git source.
git-submodule plants a submodule's .git in the work tree: a repository
of its own whose configuration names a filter, and a file naming a
repository elsewhere. The fixture withsub has gitsrc as its submodule
sub.
Diffstat (limited to 'tests/scenarios.nix')
| -rw-r--r-- | tests/scenarios.nix | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/scenarios.nix b/tests/scenarios.nix index 85b481e..d12dcd1 100644 --- a/tests/scenarios.nix +++ b/tests/scenarios.nix @@ -2105,6 +2105,66 @@ assert !(krops.isLocalTarget (targets.remote "/")); } ]; })) + # A Git work tree whose submodule's .git, which Git uses as it finds it, + # isn't the gitfile git clone made, naming the repository in + # .git/modules: a repository of its own, whose configuration names a + # command, and a gitfile naming a repository elsewhere. + (s "git-submodule" (let + elsewhere = "/var/krops-elsewhere"; + url = dirOf gitUrl + "/withsub.git"; + git = reclone: { x.git = { inherit url reclone; ref = "master"; }; }; + untouched = '' + test ! -e ${elsewhere}/ran || fail "a command in a .git directory ran" + expect_eq "HEAD elsewhere" "$(git -C ${elsewhere}/repo rev-parse HEAD)" ${gitFirst} + ''; + in { + isolate = true; + prepare = '' + rm -fR ${elsewhere} + git clone -q ${gitUrl} ${elsewhere}/repo + git -C ${elsewhere}/repo checkout -q ${gitFirst} + ''; + phases = [ + { + sources = git false; + check = untouched + '' + expect_eq "sub HEAD" "$(git -C "$T"/x/sub rev-parse HEAD)" ${gitHead} + ''; + mutate = '' + rm "$T"/x/sub/.git + cp -R "$T"/x/.git/modules/sub "$T"/x/sub/.git + git config --file "$T"/x/sub/.git/config --unset core.worktree + git config --file "$T"/x/sub/.git/config \ + filter.x.smudge "touch ${elsewhere}/ran; cat" + echo '* filter=x' > "$T"/x/sub/.git/info/attributes + git -C "$T"/x/sub update-ref --no-deref HEAD ${gitFirst} + git -C "$T"/x/sub read-tree ${gitFirst} + rm "$T"/x/sub/two + ''; + } + { + sources = git false; + expect.fail = "error: populate doesn't use the Git work tree"; + check = untouched; + mutate = '' + rm -fR "$T"/x/sub + mkdir "$T"/x/sub + echo gitdir: ${elsewhere}/repo/.git > "$T"/x/sub/.git + ''; + } + { + sources = git false; + expect.fail = "error: populate doesn't use the Git work tree"; + check = untouched; + } + { + sources = git true; + check = untouched + '' + expect_eq "sub HEAD" "$(git -C "$T"/x/sub rev-parse HEAD)" ${gitHead} + ''; + } + ]; + })) # A ref that git fetch would take for an option: --upload-pack runs a # command where the repository is local. (s "git-ref-option" (let |
