Skip to content

Commit d3970dd

Browse files
committed
render plain text file if the LFS object doesn't exist
1 parent fb271d1 commit d3970dd

File tree

7 files changed

+17
-2
lines changed

7 files changed

+17
-2
lines changed

routers/web/repo/view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func getFileReader(ctx gocontext.Context, repoID int64, blob *git.Blob) ([]byte,
234234
}
235235

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

tests/gitea-repositories-meta/user2/lfs.git/objects/30/77e1c4c8964613df72c37d14275c1eda5228a9

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
xK��OR0�0`p�� �t
2+
��s��MQH��)I-��I+VH�LK3rS��S�,ݒԊ.-���t"U&e��23�,1'�8���A�
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
73cf03db6ece34e12bf91e8853dc58f678f2f82d
1+
e9c32647bab825977942598c0efa415de300304b

tests/integration/lfs_view_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,17 @@ func TestLFSRender(t *testing.T) {
8080
content := doc.Find("div.file-view").Text()
8181
assert.Contains(t, content, "Testing READMEs in LFS")
8282
})
83+
84+
// check that an invalid lfs entry defaults to plaintext
85+
t.Run("Invalid", func(t *testing.T) {
86+
defer tests.PrintCurrentTest(t)()
87+
88+
req := NewRequest(t, "GET", "/user2/lfs/src/branch/master/invalid")
89+
resp := session.MakeRequest(t, req, http.StatusOK)
90+
91+
doc := NewHTMLParser(t, resp.Body).doc
92+
93+
content := doc.Find("div.file-view").Text()
94+
assert.Contains(t, content, "oid sha256:9d178b5f15046343fd32f451df93acc2bdd9e6373be478b968e4cad6b6647351")
95+
})
8396
}

0 commit comments

Comments
 (0)