Skip to content

feat(spec): resolve templates from a direct git url@ref - #217

Merged
w4bremer merged 1 commit into
mainfrom
feat/template-git-url
Jun 5, 2026
Merged

feat(spec): resolve templates from a direct git url@ref#217
w4bremer merged 1 commit into
mainfrom
feat/template-git-url

Conversation

@w4bremer

@w4bremer w4bremer commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a third way to resolve a solution target's template, alongside a local folder and a registry package: a direct git URL with a ref.

targets:
  - name: go-sdk
    inputs: [counter.idl]
    output: ./out
    template: https://github.com/me/template.git@v1.2.0
  - name: ssh-example
    template: git@github.com:me/template.git@main

The ref may be a tag, branch, or commit. The repository is cloned into the template cache, checked out at the ref, and used exactly like a registry template (it must contain templates/ and rules.yaml).

Resolution order

A template value is resolved in this order:

  1. Local folder<solution-dir>/<template> is a directory
  2. Direct git URLhttps://, http://, ssh://, git://, file://, or scp-style user@host:path, with the ref after the path's @
  3. Registry package — e.g. apigear-io/template-cpp

Git URLs are detected before the registry lookup, so an scp URL (which contains two @) never reaches the registry repo-id parser. Local-folder and registry resolution are unchanged for all existing inputs.

Implementation

  • repos.IsGitURL / SplitGitURLVersion / RepoNameFromGitURL — detect a git URL and derive a host-qualified cache key. The version split is anchored to the URL path, so scp user@host, HTTP credentials, and slash-bearing branch names all parse correctly. The https and scp forms of a repo map to the same cache entry.
  • repos.GetOrInstallTemplateFromGitURL + cache.InstallRef — clone and check out a ref, reusing the cache when present. The existing registry path (Install / CheckoutTag) is untouched.
  • git.CheckoutRef — resolves a ref as tag → local branch → origin/<ref> → commit hash, then checks out the resolved hash.
  • spec.compute — routes git URLs to the new resolver before the registry.
  • Schema: the template description documents the new form (no structural change).

Notes

  • The cache is keyed by name@ref, consistent with the existing registry flow. For immutable refs (tags/commits) this is ideal; a branch ref is cached and not re-pulled until the cache entry is removed.

Testing

  • Unit tests for URL detection, version splitting, and cache-key derivation.
  • Integration tests (real clones from a local repo, offline) for ref checkout, install/caching, and the solution-target wiring.
  • A regression test verifying scp-style URLs route to the git resolver rather than crashing the CLI.
  • Full suite passes with -race; gofmt/go vet clean. Verified end-to-end through the CLI against a file:// template.

Add a third way to resolve a solution target's template, alongside a
local folder and a registry package: a direct git url with a ref, e.g.

    template: https://github.com/me/template.git@v1.2.0
    template: git@github.com:me/template.git@main

The ref may be a tag, branch or commit. The repo is cloned into the
template cache, checked out at the ref, and used like any other template.

- repos: IsGitURL / SplitGitURLVersion / RepoNameFromGitURL detect a git
  url and derive a host-qualified cache key (works for any host, and the
  https and scp forms of a repo share a cache entry).
- repos: GetOrInstallTemplateFromGitURL + cache.InstallRef clone & check
  out a ref, reusing the cache when present. Install/CheckoutTag (the
  registry path) are left untouched.
- git: CheckoutRef resolves a ref as tag -> branch -> origin/<ref> ->
  commit and checks out the resolved hash.
- spec: compute() detects git urls before the registry, so an scp url
  (two '@') never reaches the registry repo-id parser, which os.Exit()s
  on such input. Local and registry resolution are unchanged.

Developed test-first; full suite green with -race.
@w4bremer
w4bremer merged commit 56428c5 into main Jun 5, 2026
6 checks passed
@w4bremer
w4bremer deleted the feat/template-git-url branch June 5, 2026 10:01
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.

1 participant