Skip to content

Fix bundle() missing git_checkout for non-default branch names#233

Closed
mari0d wants to merge 2 commits into
zeek:masterfrom
mari0d:fix/bundle-missing-git-checkout
Closed

Fix bundle() missing git_checkout for non-default branch names#233
mari0d wants to merge 2 commits into
zeek:masterfrom
mari0d:fix/bundle-missing-git-checkout

Conversation

@mari0d

@mari0d mari0d commented Jul 2, 2026

Copy link
Copy Markdown

Fixes #232.

Problem

bundle() calls git_clone() but never calls git_checkout() afterwards — the return value of git_clone() is discarded. When bundling via --manifest with a non-default branch name, the clone lands on the remote's default branch HEAD and that is what gets archived into the bundle, not the requested branch.

Every other code path in the manager (_info(), test(), _install()) correctly calls git_checkout() after cloning. bundle() was the only exception.

Fix

Capture the git.Repo return value from git_clone() and call git_checkout(clone, version) when version is a non-empty, non-SHA1 ref (branch name or tag).

SHA1 versions are intentionally excluded: they use a full clone (shallow=False) so the correct commit is reachable, and unbundle()_install() already calls git_checkout() at install time with full history available.

Test

Added testing/tests/bundle-non-default-branch which:

  1. Creates a test package with a feature-branch that has distinct content from main
  2. Bundles it via --manifest (fresh-clone path, prefer_existing_clones=False)
  3. Extracts the bundle archive directly (bypassing zkg unbundle, which masks the bug by calling git_checkout itself) and verifies the working tree contains the feature branch content

AI Disclosure

This fix was developed with assistance from Claude Code (Anthropic Claude Sonnet 4.6). The bug was identified, the fix was written, and the regression test was authored with AI assistance. I reviewed, understood, and validated all changes before submission.

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.
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 <noreply@anthropic.com>
@mari0d mari0d closed this Jul 2, 2026
@mari0d
mari0d deleted the fix/bundle-missing-git-checkout branch July 2, 2026 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants