Skip to content

feat: add LFS snapshot support to git strategy#191

Draft
joshfriend wants to merge 1 commit intomainfrom
jf/lfs-snapshot
Draft

feat: add LFS snapshot support to git strategy#191
joshfriend wants to merge 1 commit intomainfrom
jf/lfs-snapshot

Conversation

@joshfriend
Copy link
Contributor

@joshfriend joshfriend commented Mar 13, 2026

When lfs-snapshot-enabled = true in the git strategy block, cachew generates a separate LFS object archive on each snapshot interval, served at GET /git/{host}/{path}/lfs-snapshot.tar.zst.

After each git snapshot, generateAndUploadLFSSnapshot clones the mirror into a temp dir, injects a short-lived GitHub App token, runs git lfs fetch origin HEAD, then archives the resulting .git/lfs/ tree. Paths inside the archive are stored relative to .git/ (i.e. ./lfs/objects/xx/yy/sha256), so a client can extract directly into the repo's .git/ directory. The archive is served via the existing serveCachedArtifact helper with standard 200/304/404 behaviour.

A new snapshot.CreateSubdir helper in the snapshot package supports archiving a named subdirectory within a parent directory while preserving the subdirectory prefix in tar paths.

strategy "git" {
  snapshot-interval    = "1h"
  lfs-snapshot-enabled = true   # off by default; requires git-lfs and a configured GitHub App
}

LFS snapshot jobs run on the same periodic schedule as git snapshots and are registered for both newly cloned repos and repos discovered on startup.

@alecthomas alecthomas changed the title Add LFS snapshot support to git strategy feat: add LFS snapshot support to git strategy Mar 16, 2026
@joshfriend joshfriend force-pushed the jf/lfs-snapshot branch 4 times, most recently from 3a839c1 to 5b3f47d Compare March 16, 2026 15:09
Adds a parallel cachew-native LFS caching path alongside the primary
cigitcache integration. When lfs-snapshot-enabled = true in the git
strategy block, cachew runs git lfs fetch after each snapshot generation
and archives the resulting .git/lfs/ tree as a separate
lfs-snapshot.tar.zst, served at GET /git/{host}/{path}/lfs-snapshot.tar.zst.

The archive stores paths relative to .git/ (./lfs/objects/xx/yy/sha256)
so the blox client can extract it directly into the repo's .git/ directory.

Changes:
- snapshot.CreateSubdir: new helper that archives a named subdirectory
  within a parent dir, preserving the subdir prefix in tar paths.
- Strategy.generateAndUploadLFSSnapshot: clones the mirror to a temp dir,
  injects a short-lived GitHub App token into the remote URL, runs
  git lfs fetch origin HEAD, then calls CreateSubdir on .git/lfs/.
- Strategy.handleLFSSnapshotRequest: serves cached LFS archives via the
  existing serveCachedArtifact helper (304 / 200 / 404 behaviour).
- Config.LFSSnapshotEnabled: opt-in per-repo config flag (default false).
- Schedule LFS jobs on the same interval as git snapshots.

This is the fallback path for repos or branches not covered by cigitcache.
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