Skip to content

Commit

Permalink
render plain text file if the LFS object doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
bohde committed Aug 9, 2024
1 parent fb271d1 commit d3970dd
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion routers/web/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func getFileReader(ctx gocontext.Context, repoID int64, blob *git.Blob) ([]byte,
}

meta, err := git_model.GetLFSMetaObjectByOid(ctx, repoID, pointer.Oid)
if err != nil && err != git_model.ErrLFSObjectNotExist { // fallback to plain file
if err != nil && err == git_model.ErrLFSObjectNotExist { // fallback to plain file
return buf, dataRc, &fileInfo{isTextFile, false, blob.Size(), nil, st}, nil
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
xK��OR0�0`p�� �t
��s��MQH��)I-��I+VH�LK3rS��S�,ݒԊ.-���t"U&e��23�,1'�8���A�
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
73cf03db6ece34e12bf91e8853dc58f678f2f82d
e9c32647bab825977942598c0efa415de300304b
13 changes: 13 additions & 0 deletions tests/integration/lfs_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,17 @@ func TestLFSRender(t *testing.T) {
content := doc.Find("div.file-view").Text()
assert.Contains(t, content, "Testing READMEs in LFS")
})

// check that an invalid lfs entry defaults to plaintext
t.Run("Invalid", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()

req := NewRequest(t, "GET", "/user2/lfs/src/branch/master/invalid")
resp := session.MakeRequest(t, req, http.StatusOK)

doc := NewHTMLParser(t, resp.Body).doc

content := doc.Find("div.file-view").Text()
assert.Contains(t, content, "oid sha256:9d178b5f15046343fd32f451df93acc2bdd9e6373be478b968e4cad6b6647351")
})
}

0 comments on commit d3970dd

Please sign in to comment.