Skip to content

feat: replicate canonical Git LFS pointers before publishing refs - #36

Merged
vmvarela merged 5 commits into
masterfrom
feat/git-lfs-transfer
Oct 30, 2026
Merged

vmvarela merged 5 commits into
masterfrom
feat/git-lfs-transfer

Conversation

@vmvarela

Copy link
Copy Markdown
Owner

What

When refs is selected and the source contains Git LFS pointers, gh-replicate now downloads the LFS objects, verifies them and uploads them to the destination before publishing any ref, instead of stopping. The run still stops safely on anything it cannot transfer.

Why

Fixes the core of #5: a repository with Git LFS used to be rejected entirely (fail-fast) because pushing pointers without their objects would leave the destination broken. This delivers LFS support for the common case while keeping that barrier for everything else.

How

  • syncGit now runs in a fresh, private, ephemeral bare repository with isolated configuration, instead of the shared incremental cache. Credentials and endpoints are pinned per side (lfs.url/lfs.pushurl), and the cache lock still serialises runs of the same source.
  • The LFS scan classifies each reachable blob into three outcomes: no LFS, a canonical spec-v1 pointer (supported), or an unsupported/ambiguous candidate (blocked). Only canonical pointers — version https://git-lfs.github.com/spec/v1, exactly three LF lines, no extensions, smaller than 1024 bytes — are transferred.
  • git lfs fetch --all --stdin downloads the objects, each is checked for existence, size and SHA-256, then git lfs push --all --stdin uploads them, before Actions are disabled and refs are pushed atomically.
  • git-lfs 3.8.1 or newer is required only when LFS is confirmed; repositories without LFS need no change.
  • A hostile environment cannot steer the transfer: inherited Git overrides that redirect the repository or truncate history are rejected, and HEAD is pointed at an absent ref so a committed .lfsconfig is never read.

How tested

  • go test -race -count=1 -timeout 3m ./... — 165 tests.
  • go test -race -tags=lfsintegration ./... — adds a real git-lfs 3.8.1 transfer against a synthetic HTTP LFS batch server (download from the source, verify, upload to the destination).
  • go vet ./..., gofmt -l ., git diff --check — clean.

Remaining work

  • Only canonical spec-v1 pointers are transferred. Older version aliases (hawser, git-media), CRLF, padding, extensions and unrecognised versions still stop the run. Supporting those is follow-up, so this does not close Replicate Git LFS objects before updating destination refs #5.
  • The transfer is validated against a synthetic HTTP LFS server, not GitHub's live LFS endpoints; the HTTPS path reuses the same lfs.url pinning and gh auth git-credential helper the existing git fetch uses.
  • Source history is no longer reused across runs (the incremental cache is unused), so each run re-downloads it. Kept simple and safe over fast.

Comment thread lfs_auxiliary.go Fixed
Comment thread lfs_objects.go Fixed
Address review findings on the canonical LFS transfer:

- pushRefs now publishes through the isolated lfsRun environment (pinned
  endpoints, side token, cache lock), so inherited config cannot redirect it.
- pointHEADAbsent uses refs/gh-replicate/ (outside fetched namespaces) and
  verifies HEAD does not resolve, so a committed .lfsconfig is never read.
- cancellation kills the whole process group on Unix, not just the direct git,
  so a git-lfs descendant cannot outlive the ephemeral bare.
- lfsSideEnv preserves lowercase proxy variables as well as uppercase.
- ci.yml filter references the renamed TestSyncGitLifecycle.
Comment thread lfs_proc_unix.go Fixed
- Block LFS transfer on platforms without whole-tree cancellation (Windows).
- Fail closed when the ephemeral HEAD unexpectedly resolves.
- Prove per-side credential separation (unit test + external proxy/CA ensayo).
- Assert dry-run makes no LFS requests and an upload failure stops before
  Actions or any ref push.
- Build-tag the process-tree test to unix.
- Document best-effort cleanup and possible orphaned upload objects.
@vmvarela
vmvarela merged commit f0fa0c6 into master Oct 30, 2026
19 checks passed
@vmvarela vmvarela added the enhancement New feature or request label Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replicate Git LFS objects before updating destination refs

2 participants