From 2f96d4b9b95dbef6e0f97a0ec66b3af54f9042dc Mon Sep 17 00:00:00 2001 From: Mario De Tore Date: Thu, 2 Jul 2026 06:57:00 +0700 Subject: [PATCH 1/2] Fix bundle() missing git_checkout for non-default branch names When bundling packages via --manifest with a fresh clone (package not already installed), bundle() called git_clone() but never called git_checkout() afterwards. This caused the bundled working tree to always reflect the remote default branch HEAD, regardless of the version specified in the manifest. All other code paths (_info(), test(), _install()) correctly call git_checkout() after cloning. The fix captures the git.Repo return value from git_clone() and calls git_checkout() when version is a non-SHA1 ref (branch name or tag). SHA1 versions are unaffected: the correct version is checked out at unbundle/install time via _install() which has access to the full git history (shallow=False for SHA1s). Adds a regression test that bundles a package pinned to a non-default branch via --manifest and verifies the bundle archive contains the correct working tree content. --- .../foo.__load__.zeek | 2 + .../installed.out | 2 + testing/tests/bundle-non-default-branch | 38 +++++++++++++++++++ zeekpkg/manager.py | 8 +++- 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 testing/baselines/tests.bundle-non-default-branch/foo.__load__.zeek create mode 100644 testing/baselines/tests.bundle-non-default-branch/installed.out create mode 100644 testing/tests/bundle-non-default-branch diff --git a/testing/baselines/tests.bundle-non-default-branch/foo.__load__.zeek b/testing/baselines/tests.bundle-non-default-branch/foo.__load__.zeek new file mode 100644 index 0000000..8af7022 --- /dev/null +++ b/testing/baselines/tests.bundle-non-default-branch/foo.__load__.zeek @@ -0,0 +1,2 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +print "feature branch content"; diff --git a/testing/baselines/tests.bundle-non-default-branch/installed.out b/testing/baselines/tests.bundle-non-default-branch/installed.out new file mode 100644 index 0000000..9b2d1fe --- /dev/null +++ b/testing/baselines/tests.bundle-non-default-branch/installed.out @@ -0,0 +1,2 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +one/alice/foo (installed: feature-branch) diff --git a/testing/tests/bundle-non-default-branch b/testing/tests/bundle-non-default-branch new file mode 100644 index 0000000..bdade37 --- /dev/null +++ b/testing/tests/bundle-non-default-branch @@ -0,0 +1,38 @@ +# Regression test: bundle() must check out the requested non-default branch +# when doing a fresh clone (i.e. when bundling via --manifest). +# +# Previously, git_clone() was called but git_checkout() was never called in +# bundle(), so the working tree inside the bundle always reflected the remote +# default branch HEAD regardless of the requested version. +# +# We test by inspecting the raw bundle archive contents, which is not affected +# by the git_checkout() call in unbundle() -> _install(). +# +# @TEST-EXEC: bash %INPUT +# @TEST-EXEC: $TEST_BASE/../zkg --configfile=config bundle --force --manifest manifest.ini -- test.bundle +# @TEST-EXEC: tar -xzf test.bundle foo/__load__.zeek +# @TEST-EXEC: btest-diff foo/__load__.zeek + +# Create a non-default branch on foo with distinct content. +# foo uses 'main' as default branch (see testing/scripts/initializer). +cd packages/foo +export FOO_URL=$(pwd) +echo 'print "main content";' > __load__.zeek +git commit -am 'main content' + +git checkout -b feature-branch +echo 'print "feature branch content";' > __load__.zeek +git commit -am 'feature branch content' + +# Advance main past feature-branch so they are clearly distinct. +git checkout main +echo 'print "main advanced content";' > __load__.zeek +git commit -am 'advance main' + +cd - + +# Write manifest INI referencing foo by local path and the non-default branch. +cat > manifest.ini < Date: Thu, 2 Jul 2026 19:54:54 +0700 Subject: [PATCH 2/2] test: add diagnostics to bundle-non-default-branch test Add cat manifest.ini and tar -tzf steps to surface the actual bundle contents in the btest diag on CI failure. Co-Authored-By: Claude Sonnet 4.6 --- testing/tests/bundle-non-default-branch | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/testing/tests/bundle-non-default-branch b/testing/tests/bundle-non-default-branch index bdade37..3c80a5e 100644 --- a/testing/tests/bundle-non-default-branch +++ b/testing/tests/bundle-non-default-branch @@ -8,15 +8,17 @@ # We test by inspecting the raw bundle archive contents, which is not affected # by the git_checkout() call in unbundle() -> _install(). # -# @TEST-EXEC: bash %INPUT +# @TEST-EXEC: bash -euo pipefail %INPUT +# @TEST-EXEC: cat manifest.ini # @TEST-EXEC: $TEST_BASE/../zkg --configfile=config bundle --force --manifest manifest.ini -- test.bundle +# @TEST-EXEC: tar -tzf test.bundle # @TEST-EXEC: tar -xzf test.bundle foo/__load__.zeek # @TEST-EXEC: btest-diff foo/__load__.zeek # Create a non-default branch on foo with distinct content. # foo uses 'main' as default branch (see testing/scripts/initializer). cd packages/foo -export FOO_URL=$(pwd) +FOO_URL=$(pwd) echo 'print "main content";' > __load__.zeek git commit -am 'main content'