Skip to content

feat: template caching for git-sourced templates#3

Merged
raiderrobert merged 4 commits into
feat/m2-git-clonefrom
feat/m2-template-caching
Feb 12, 2026
Merged

feat: template caching for git-sourced templates#3
raiderrobert merged 4 commits into
feat/m2-git-clonefrom
feat/m2-template-caching

Conversation

@raiderrobert

@raiderrobert raiderrobert commented Feb 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • Cache cloned templates at ~/.cache/diecut/templates/ (XDG-compliant via dirs crate)
  • Deterministic cache keys with URL normalization (trailing .git, slashes)
  • get_or_clone() checks cache before cloning, with cross-filesystem rename fallback
  • list_cached() for enumerating cached templates with metadata
  • clear_cache() for selective or full cache removal

Stacks on #2 (git clone via gix).

Test plan

  • cargo clippy with -Dwarnings passes
  • cargo test passes (cache key tests, XDG path test)
  • CI pipeline passes
  • Manual test: second diecut new gh:user/repo hits cache instead of re-cloning

- Cache cloned templates at ~/.cache/diecut/templates/ (XDG-compliant)
- Deterministic cache keys with URL normalization (trailing .git, slashes)
- get_or_clone() checks cache before cloning, with cross-filesystem fallback
- list_cached() for enumerating cached templates with metadata
- clear_cache() for selective or full cache removal
- Cache metadata stored as .diecut-cache.toml per entry

Closes diecut-l41
…lity)

- Rename chrono_now() to unix_timestamp_secs(), update doc comments
- Add normalize_url() helper for consistent URL comparison in clear_cache
- Make get_cache_dir() configurable via DIECUT_CACHE_DIR env var, return Result
- Reject file:// URLs in clone_template, warn on http://
- Move create_dir_all before clone operation in get_or_clone
- Add UnsafeUrl error variant for URL scheme validation
- Add tests for env var, URL normalization, and file:// rejection
Change get_or_clone to keep TempDir alive during cache placement.
On error, TempDir drops and cleans up automatically. Only call
tmp_dir.keep() after successful rename/copy into the cache directory.
This prevents orphaned temp directories when metadata write, mkdir,
or rename operations fail.
Add blocking-http-transport-reqwest-rust-tls feature to gix dependency.
Without this, only file://, git://, and ssh:// transports were available,
causing HTTPS clones (gh: abbreviations, https:// URLs) to fail silently.
@raiderrobert raiderrobert merged commit 02d28b1 into feat/m2-git-clone Feb 12, 2026
1 check passed
raiderrobert added a commit that referenced this pull request Feb 12, 2026
feat: template caching for git-sourced templates
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