feat(spec): resolve templates from a direct git url@ref - #217
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.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/andrules.yaml).Resolution order
A
templatevalue is resolved in this order:<solution-dir>/<template>is a directoryhttps://,http://,ssh://,git://,file://, or scp-styleuser@host:path, with the ref after the path's@apigear-io/template-cppGit 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 scpuser@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.templatedescription documents the new form (no structural change).Notes
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
-race;gofmt/go vetclean. Verified end-to-end through the CLI against afile://template.