Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software/vole.git

Self-hosted forge that lives in your Git repo.

Resolve LFS pointers in release source archives

dc98c26d4eb07402ddd65b6c05aa70429ce618b3 · Keenan Nemetz · 13d ago · parent 617cda58

Resolve LFS pointers in release source archives

A release tarball is generated by git archive from the bare server repository,
which has no filter.lfs.smudge. Pointer blobs were copied verbatim, so a source
archive of a game project held 130-byte pointers where textures and levels
should be.

ArchiveResolvingLFS streams git's uncompressed tar through a rewrite: a small
regular file that parses as a pointer is replaced by the object from the
repository's LFS namespace, and tar.gz is compressed in process so every entry
is visible. Non-pointer files stream through, including files larger than the
pointer cap that begin with the same version line. A missing object fails the
archive rather than shipping the pointer silently.

The release page says the contents are included, and the archive ETag gains a
version suffix so a cached pointer tarball is revalidated after the change.

server/releases_test.go +37−10

@@ -106,9 +106,9 @@ func TestReleaseListAndNotes(t *testing.T) {
106 106 t.Fatalf("release page still shows %q:\n%s", unwanted, page)
107 107 }
108 108 }
109 // A repository with no LFS attributes gets no LFS warning.
110 if strings.Contains(page, "pointer files") {
111 t.Fatalf("release page warns about LFS in a repository that does not use it:\n%s", page)
109 // A repository with no LFS attributes gets no LFS note.
110 if strings.Contains(page, "Files tracked with Git LFS") {
111 t.Fatalf("release page mentions LFS in a repository that does not use it:\n%s", page)
112 112 }
113 113 // The first release has no previous tag to range over, and still renders.
114 114 if code, first := f.get("/" + f.repo + "/releases/v0.9.0"); code != 200 || !strings.Contains(first, "beta") {
@@ -281,15 +281,23 @@ func TestReleaseNotesAreSanitised(t *testing.T) {
281 281 }
282 282 }
283 283
284 // TestReleasePageWarnsAboutLFSPointers checks that git archive copies pointer
285 // files verbatim, so a tarball of an LFS repository is not the bytes the reader
286 // expects. The page has to say so.
287 func TestReleasePageWarnsAboutLFSPointers(t *testing.T) {
284 // TestReleaseArchiveResolvesLFSPointers checks that a source archive holds the
285 // bytes a game project needs, not the pointer files git stores. A tarball with a
286 // 130-byte pointer where a texture should be is not a source release.
287 func TestReleaseArchiveResolvesLFSPointers(t *testing.T) {
288 288 t.Parallel()
289 289 f := newFixture(t)
290 290 f.publish(f.repo)
291
292 asset := []byte("the real texture bytes\x00\x01\x02")
293 oid, err := f.srv.LFS.PutBytes(f.repo, asset)
294 if err != nil {
295 t.Fatal(err)
296 }
297 pointer := fmt.Sprintf("version https://git-lfs.github.com/spec/v1\noid sha256:%s\nsize %d\n", oid, len(asset))
291 298 work := workRepo(t, map[string]string{
292 299 ".gitattributes": "*.bin filter=lfs diff=lfs merge=lfs -text\n",
300 "art/hero.bin": pointer,
293 301 "readme.md": "x\n",
294 302 })
295 303 if _, errs, err := f.git(work, "push", f.sshURL(f.repo), "main:refs/heads/main"); err != nil {
@@ -302,14 +310,33 @@ func TestReleasePageWarnsAboutLFSPointers(t *testing.T) {
302 310 t.Fatalf("push tag: %s", errs)
303 311 }
304 312
313 for _, tc := range []struct {
314 ext string
315 gzipped bool
316 }{
317 {"archive.tar", false},
318 {"archive.tar.gz", true},
319 } {
320 code, body := f.get("/" + f.repo + "/releases/v1.0.0/" + tc.ext)
321 if code != 200 {
322 t.Fatalf("%s = %d", tc.ext, code)
323 }
324 files := tarContents(t, strings.NewReader(body), tc.gzipped)
325 if got := files[f.repo+"-v1.0.0/art/hero.bin"]; got != string(asset) {
326 t.Fatalf("%s hero.bin = %q, want the stored object", tc.ext, got)
327 }
328 if strings.Contains(files[f.repo+"-v1.0.0/art/hero.bin"], "git-lfs.github.com") {
329 t.Fatalf("%s still contains the pointer", tc.ext)
330 }
331 }
332
305 333 code, page := f.get("/" + f.repo + "/releases/v1.0.0")
306 334 if code != 200 {
307 335 t.Fatalf("release page = %d", code)
308 336 }
309 if !strings.Contains(page, "pointer files") {
310 t.Fatalf("release page does not warn about LFS pointers:\n%s", page)
337 if !strings.Contains(page, "included as their") {
338 t.Fatalf("release page does not say LFS contents are included:\n%s", page)
311 339 }
312
313 340 }
314 341
315 342 func TestReleaseArchiveIsGeneratedFromTheTag(t *testing.T) {