Skip to content

bundle() does not check out requested version for non-default branch names #232

Description

@mari0d

Summary

zkg bundle --manifest silently produces a bundle containing the wrong working tree when a manifest entry specifies a non-default branch name. The bundle archives the default branch HEAD instead of the requested branch.

Root Cause

In zeekpkg/manager.py, the bundle() function calls git_clone() but never calls git_checkout() afterwards. The return value of git_clone() (a git.Repo object) is discarded. Every other code path in the manager (_info(), test(), _install()) correctly calls git_checkout() after cloning.

# manager.py — the clone result is discarded, no checkout follows
git_clone(git_url, clonepath, shallow=(not is_sha1(version)))

For non-default branch names, shallow=True is used, which fetches all remote refs (--no-single-branch), so the branch ref is present in the clone — but HEAD is never moved there. The bundle archives whatever the remote's default branch HEAD points to.

Affected version types

Version Shallow Working tree in bundle Post-unbundle
Default branch Yes Correct (by accident) Correct
Non-default branch Yes Wrong (default branch) Correct*
SHA1 No Wrong (default branch) Correct*

* unbundle() calls _install() which calls git_checkout(), so the correct version is installed on the target system regardless. However the bundled working tree itself is wrong, which matters for any use case that reads the bundle archive directly rather than going through zkg unbundle.

Steps to reproduce

# Create a repo with a non-default branch
git init mypackage && cd mypackage
echo 'print "default";' > __load__.zeek && git add . && git commit -m init
git checkout -b feature && echo 'print "feature";' > __load__.zeek && git commit -am feature
git checkout main && echo 'print "main advanced";' > __load__.zeek && git commit -am advance

# Bundle pinned to the non-default branch
cat > manifest.ini <<EOF
[bundle]
/path/to/mypackage = feature
EOF
zkg bundle --force --manifest manifest.ini -- out.bundle

# Inspect the bundle working tree (not via zkg unbundle)
tar -xzf out.bundle mypackage/__load__.zeek
cat mypackage/__load__.zeek
# Prints "main advanced" — wrong, should print "feature"

Fix

Capture the return value of git_clone() and call git_checkout() when the version is a non-empty, non-SHA1 ref. git_checkout is already imported and git_clone already returns git.Repo.

A PR with the fix and a regression test is attached: #233

AI Disclosure

This issue was filed with assistance from Claude Code (Anthropic Claude Sonnet 4.6). The bug was identified and the reproduction case was developed with AI assistance. I reviewed and validated all content before submission.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions