From b0469337bd8eb3d8e325e82640ac855731975000 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 12 Nov 2026 02:35:25 +0000 Subject: tests: deploy an older commit first in the git scenarios The git scenarios deployed only the commit a clone checks out anyway, so populate never fetched, reset, or updated submodules in a full clone, and fetchAlways made no observable difference. They deploy HEAD's parent first now. --- tests/default.nix | 7 ++++--- tests/scenarios.nix | 22 +++++++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/default.nix b/tests/default.nix index 4d0e256..ca409b3 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -5,9 +5,10 @@ { pkgs ? import ../pkgs {} }: let - # HEAD of /fixtures/gitsrc, which fixtures.sh creates deterministically. - # fixtures.sh fails if it differs, naming the actual one. + # HEAD of /fixtures/gitsrc, which fixtures.sh creates deterministically, + # and its parent. fixtures.sh fails if HEAD differs, naming the actual one. gitHead = "e42d44ef9cdb76ba5a84dff4c89c38222703bf0c"; + gitFirst = "8d47013fa0888948cf0ffcc4e3c69a7b5f180562"; scenarios = import ./scenarios.nix { inherit (pkgs) lib; @@ -18,7 +19,7 @@ let gitUrl = "git://deployer/gitsrc.git"; remoteHost = "target"; agePath = "${pkgs.age}/bin/age"; - inherit gitHead; + inherit gitHead gitFirst; }; in builtins.mapAttrs diff --git a/tests/scenarios.nix b/tests/scenarios.nix index e56cb13..4838b74 100644 --- a/tests/scenarios.nix +++ b/tests/scenarios.nix @@ -23,8 +23,9 @@ remoteHost, # Absolute path of age on the deploying machine. agePath, - # HEAD of /fixtures/gitsrc. + # HEAD of /fixtures/gitsrc, and its parent. gitHead, + gitFirst, }: let @@ -363,10 +364,10 @@ assert !(krops.isLocalTarget (targets.remote "/")); gc expect_eq msg "$(nix_eval "$T"/.populate/flakes/x#msg)" git:alt ''; - sources = { + sources = ref: { x.git = { url = gitUrl; - ref = gitHead; + inherit ref; inherit (flags) shallow fetchAlways; clean.exclude = optional flags.cleanExclude "keepme"; inputs = optionalAttrs flags.inputs { dep.follows = "alt"; }; @@ -374,15 +375,26 @@ assert !(krops.isLocalTarget (targets.remote "/")); } // optionalAttrs flags.inputs alt; in { phases = [ + # The older commit first, so deploying HEAD changes the work tree, and + # fetches if fetchAlways is set or the clone is shallow. { - inherit sources check; + sources = sources gitFirst; + check = '' + expect_eq HEAD "$(git -C "$T"/x rev-parse HEAD)" ${gitFirst} + expect_eq commits "$(git -C "$T"/x rev-list --count HEAD)" 1 + test ! -e "$T"/x/two || fail "two present" + ''; + } + { + sources = sources gitHead; + inherit check; mutate = '' echo junk > "$T"/x/junk echo keepme > "$T"/x/keepme ''; } { - inherit sources; + sources = sources gitHead; check = check + '' test ! -e "$T"/x/junk || fail "junk not cleaned" ${if flags.cleanExclude then '' -- cgit v1.3.1