Skip to content

Commit bfa91db

Browse files
committed
BLENDER: Workaround LFS files not being available in pull requests
Patch taken from upstream Gitea issue go-gitea#17715, associating the LFS pointer when the file is downloaded.
1 parent c6d90c4 commit bfa91db

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

models/git/lfs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func CountLFSMetaObjects(ctx context.Context, repoID int64) (int64, error) {
238238

239239
// LFSObjectAccessible checks if a provided Oid is accessible to the user
240240
func LFSObjectAccessible(ctx context.Context, user *user_model.User, oid string) (bool, error) {
241-
if user.IsAdmin {
241+
if user != nil && user.IsAdmin {
242242
count, err := db.GetEngine(ctx).Count(&LFSMetaObject{Pointer: lfs.Pointer{Oid: oid}})
243243
return count > 0, err
244244
}

services/lfs/server.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,26 @@ func BatchHandler(ctx *context.Context) {
246246
responseObject = buildObjectResponse(rc, p, false, !exists, err)
247247
} else {
248248
var err *lfs_module.ObjectError
249+
250+
if exists && meta == nil {
251+
accessible, accessibleErr := git_model.LFSObjectAccessible(ctx, ctx.Doer, p.Oid)
252+
if accessibleErr != nil {
253+
log.Error("Unable to check if LFS MetaObject [%s] is accessible. Error: %v", p.Oid, err)
254+
writeStatus(ctx, http.StatusInternalServerError)
255+
return
256+
}
257+
if accessible {
258+
_, newMetaObjErr := git_model.NewLFSMetaObject(ctx, repository.ID, p)
259+
if newMetaObjErr != nil {
260+
log.Error("Unable to create LFS MetaObject [%s] for %s/%s. Error: %v", p.Oid, rc.User, rc.Repo, err)
261+
writeStatus(ctx, http.StatusInternalServerError)
262+
return
263+
}
264+
} else {
265+
exists = false
266+
}
267+
}
268+
249269
if !exists || meta == nil {
250270
err = &lfs_module.ObjectError{
251271
Code: http.StatusNotFound,

0 commit comments

Comments
 (0)