Skip to content

feat: fetch a source again at the revision it was fetched at - #5

Open
jvmakine wants to merge 2 commits into
block:mainfrom
jvmakine:juho/revisions
Open

jvmakine wants to merge 2 commits into
block:mainfrom
jvmakine:juho/revisions

Conversation

@jvmakine

@jvmakine jvmakine commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Tools that generate files from a fetched source, such as scaffolder templates, sometimes need the exact same source again later, for example to re-render an old version and diff it against the latest. Fetch doesn't say which revision it fetched, and Resolve can't know it: ref=main only turns into a commit once the clone happens.

This adds an optional interface, so Resolver and Fetch are unchanged:

type RevisionResolver interface {
	Resolver
	FetchRevision(ctx context.Context, source Source, dest string) (string, error)
	AtRevision(source Source, revision string) Source
}

Fetcher (and the package-level defaults) gain:

  • FetchRevision(ctx, source, dest) (string, error): fetches like Fetch and also returns the revision.
  • AtRevision(source, revision) (string, error): returns a source string pinned to that revision, to pass to Fetch.

Both return ErrNoRevisions when the source's resolver doesn't implement the interface.

Git implements it:

  • The revision is the commit hash, read with git rev-parse HEAD after the clone.
  • AtRevision replaces ref with commit=<hash>&depth=1, so only that commit is fetched.

Other resolvers can add it later. A tarball resolver, for example, could hash the archive while downloading it, which is why the revision comes from a fetch rather than from the unpacked files.

🤖 Generated with Claude Code

jvmakine and others added 2 commits October 23, 2026 15:34
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@jvmakine
jvmakine marked this pull request as ready for review October 23, 2026 04:49
@jvmakine
jvmakine requested a review from alecthomas as a code owner October 23, 2026 04:49
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