From 36cfd6b9fa8d729172f90e8fdd507349905d4f11 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 13 Nov 2026 14:01:19 +0000 Subject: populate: follow branches and tags of git sources A ref that consists of 4 to 40 hex digits is a commit, which populate fetches only if the work tree lacks it, unless fetchAlways is set. Any other ref is a branch or tag, which populate fetches on every run, resetting the work tree to the commit fetched. Resetting to the name itself resolves to a local branch, which fetching doesn't move. --- tests/scenarios.nix | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'tests') diff --git a/tests/scenarios.nix b/tests/scenarios.nix index 4e869dc..e618fcd 100644 --- a/tests/scenarios.nix +++ b/tests/scenarios.nix @@ -595,6 +595,40 @@ assert !(krops.isLocalTarget (targets.remote "/")); } ]; })) targetKinds + # Branches and tags follow the server: a branch that moves between two + # deploys, and a tag, with full and shallow clones. + ++ concatMap (targetKind: map (shallow: scenario { + name = "git-${targetKind}-shallow${if shallow then "1" else "0"}-refs"; + inherit targetKind; + prepareDeployer = '' + git -C /fixtures/git/gitsrc.git update-ref refs/heads/moving ${gitFirst} + git -C /fixtures/git/gitsrc.git update-ref refs/tags/first ${gitFirst} + ''; + phases = [ + { + sources.x.git = { url = gitUrl; ref = "moving"; inherit shallow; }; + check = '' + expect_eq HEAD "$(git -C "$T"/x rev-parse HEAD)" ${gitFirst} + ''; + mutateDeployer = '' + git -C /fixtures/git/gitsrc.git update-ref refs/heads/moving ${gitHead} + ''; + } + { + sources.x.git = { url = gitUrl; ref = "moving"; inherit shallow; }; + check = '' + expect_eq HEAD "$(git -C "$T"/x rev-parse HEAD)" ${gitHead} + ''; + } + { + sources.x.git = { url = gitUrl; ref = "first"; inherit shallow; }; + check = '' + expect_eq HEAD "$(git -C "$T"/x rev-parse HEAD)" ${gitFirst} + ''; + } + ]; + }) [ false true ]) targetKinds + # A git source stops drawing inputs: its lock file, which Nix created and # staged, goes, so the work tree is as the commit has it. ++ map (targetKind: scenario { -- cgit v1.3.1