Skip to content

Move clone/snapshot logic onto RhizaTemplate; remove redundant _sync_helpers functions#379

Merged
tschm merged 7 commits intomainfrom
copilot/simplify-sync-command
Mar 8, 2026
Merged

Move clone/snapshot logic onto RhizaTemplate; remove redundant _sync_helpers functions#379
tschm merged 7 commits intomainfrom
copilot/simplify-sync-command

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 8, 2026

sync.py orchestrated cloning and snapshot preparation through a chain of free functions (_construct_git_url, _clone_and_resolve_upstream, _excluded_set, _prepare_snapshot) imported from _sync_helpers. These belong on the model that owns the configuration.

Changes

RhizaTemplate — three new members

  • git_url (property) — constructs the HTTPS clone URL from template_repository + template_host; raises ValueError for unsupported hosts or missing repo
  • clone(git_executable, git_env, branch="main") — sparse-clones upstream, resolves bundle names → file paths, mutates self.include; returns (upstream_dir, upstream_sha)
  • snapshot(upstream_dir, snapshot_dir) — builds the exclude set from self.exclude, copies included files into snapshot_dir; returns (materialized, excludes)

All three use deferred (function-body) imports to break the circular dependency with _sync_helpers.

_validate_and_load_template — simplified return type

Changed from returning a 5-tuple (template, rhiza_repo, rhiza_branch, include_paths, excluded_paths) to returning RhizaTemplate directly. The CLI branch arg is applied as a fallback (template.template_branch = branch) inside the function when no ref is set in template.yml.

sync.py — dramatically simplified

# before
template, rhiza_repo, rhiza_branch, include_paths, excluded_paths = _validate_and_load_template(target, branch)
git_url = _construct_git_url(rhiza_repo, rhiza_host)
upstream_dir, upstream_sha, include_paths = _clone_and_resolve_upstream(template, git_url, ...)
excludes = _excluded_set(upstream_dir, excluded_paths)
materialized = _prepare_snapshot(upstream_dir, include_paths, excludes, upstream_snapshot)

# after
template = _validate_and_load_template(target, branch)
upstream_dir, upstream_sha = template.clone(git_executable, git_env, branch=branch)
materialized, excludes = template.snapshot(upstream_dir, upstream_snapshot)

All downstream values (repo, host, ref, etc.) are read directly from template.* attributes — no local alias variables remain in sync.py.

_sync_helpers.py — dead code removed

  • Deleted _construct_git_url and _clone_and_resolve_upstream entirely
  • _excluded_set and _prepare_snapshot remain as private helpers used internally by _merge_with_base
  • Removed the top-level load_bundles_from_clone/resolve_include_paths import (now imported directly from bundle_resolver inside models.py)

materialize.py

Removed _construct_git_url from re-exports.

Tests

  • Removed TestConstructGitUrl from test_sync.py; updated TestCloneAndResolveUpstreamWithTemplates to exercise RhizaTemplate.clone directly
  • E2e tests patching sync._clone_and_resolve_upstream updated to patch RhizaTemplate.clone
  • TestValidateAndLoadTemplate updated to assert on the returned RhizaTemplate directly; added test_branch_fallback_applied_when_template_branch_unset
  • Added TestRhizaTemplateGitUrl, TestRhizaTemplateClone, TestRhizaTemplateSnapshot to test_models.py
Original prompt

This section details on the original issue you should resolve

<issue_title>Simplify the sync command</issue_title>
<issue_description>I want to do

template = RhizaTemplate.from_yaml(target / ".rhiza" / "template.yml")

#template = _validate_and_load_template(target)
#rhiza_host = template.template_host or "github"
#git_url = _construct_git_url(rhiza_repo, rhiza_host)
#git_url = template.git_url

# clone and resolve the template repository
upstream_dir, upstream_sha = template.clone(
    git_executable,
    git_env,
)

#logger.info(f"Cloning {rhiza_repo}@{rhiza_branch} (upstream)")
#upstream_dir, upstream_sha, include_paths = _clone_and_resolve_upstream(
#    template,
#    git_url,
#    rhiza_branch,
#    git_executable,
#    git_env,
#)

e.g. clone should be a function of the RhizaTemplate class</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: tschm <2046079+tschm@users.noreply.github.com>
@tschm tschm marked this pull request as ready for review March 8, 2026 04:35
…helpers functions

Co-authored-by: tschm <2046079+tschm@users.noreply.github.com>
Copilot AI changed the title [WIP] Simplify sync command implementation Move clone/snapshot logic onto RhizaTemplate; remove redundant _sync_helpers functions Mar 8, 2026
Copilot finished work on behalf of tschm March 8, 2026 04:37
@tschm
Copy link
Copy Markdown
Member

tschm commented Mar 8, 2026

@copilot: Should be enough to return RhizaTemplate from the _validate... function

Co-authored-by: tschm <2046079+tschm@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 8, 2026

@copilot: Should be enough to return RhizaTemplate from the _validate... function

Done in 22e337b. _validate_and_load_template now returns RhizaTemplate directly. The CLI branch arg is applied as a fallback (template.template_branch = branch) inside the function when no ref is set in template.yml. sync.py reads template.template_repository, template.template_branch, template.template_host, etc. directly — no local alias variables remain.

Copilot finished work on behalf of tschm March 8, 2026 04:45
tschm and others added 3 commits March 8, 2026 08:50
@tschm tschm merged commit 71e7163 into main Mar 8, 2026
16 checks passed
@tschm tschm deleted the copilot/simplify-sync-command branch March 8, 2026 05:14
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.

Simplify the sync command

2 participants